当前位置: 代码迷 >> JavaScript >> angularJS使用有角度的谷歌地图找到位置/地名
  详细解决方案

angularJS使用有角度的谷歌地图找到位置/地名

热度:65   发布时间:2023-06-05 15:56:23.0

我想找到用户在地图上选择的location name 目前我正在获得经纬度。 但无法获得位置名称。

我正在使用angularJSangular-google-maps 2.1.5.

这是html。

<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" events="map.events">

</ui-gmap-google-map>

JS:

$scope.map = {
      center: {
        latitude: 21.0000,
        longitude: 78.0000
      },
      zoom: 4,
      events: {
        click: function(mapModel, eventName, originalEventArgs,ok) {
          var e = originalEventArgs[0]; 

            objOneDevice.dev_latitude = e.latLng.lat();
            objOneDevice.dev_longitude = e.latLng.lng();

            $scope.templatedInfoWindow.show = true;

        }
      }
    };
    $scope.options = {
      scrollwheel: true
    };

任何事情都表示赞赏。

这是我使用所做的。

$scope.map = {
      center: {
        latitude: 21.0000,
        longitude: 78.0000
      },
      zoom: 4,
      events: {
        click: function(mapModel, eventName, originalEventArgs,ok) {
          var e = originalEventArgs[0]; 

            var geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(e.latLng.lat(), e.latLng.lng());

            geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        if (results[1]) {

                            console.log(results[1].formatted_address); // details address
                        } else {
                            console.log('Location not found');
                        }
                    } else {
                        console.log('Geocoder failed due to: ' + status);
                    }
                });


        }
      }
    };

在给定纬度/经度对象的情况下,您可以使用Google Map API将位置映射到大致地址。 您可以使用地理编码API将位置映射到地址和地址。

Geocoder.geocode( { 'latLng': latLngObject }, callbackFn);

是Google Map API进行地理编码的链接。

试试这些链接

使用地理编码API将位置映射到地址和地址。

Geocoder.geocode({'latLng':latLngObject},回调);

希望能帮助到你!!!