【问题标题】:angularJS find the location/place name using angular google mapangularJS 使用 Angular 谷歌地图查找位置/地名
【发布时间】:2015-08-07 05:40:36
【问题描述】:

我想找到用户在地图上选择的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
    };

任何事情都值得赞赏。

【问题讨论】:

    标签: javascript angularjs html google-maps geolocation


    【解决方案1】:

    这是我使用 Reverse geocoding 所做的。

    $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);
                        }
                    });
    
    
            }
          }
        };
    

    【讨论】:

    • 您为什么不接受自己的答案作为解决方案?
    【解决方案2】:

    给定纬度/经度对象,您可以使用 Google Map API 将位置映射到大致地址。 您可以使用 Geocoding API 将位置映射到地址以及将地址映射到位置。

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

    Here 是 Google Map API for Geocoding 的链接。

    【讨论】:

    • 有没有其他方法可以使用角度方式来实现?
    【解决方案3】:

    试试这些链接 https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse?csw=1

    使用地理编码 API 将位置映射到地址以及将地址映射到位置。 http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

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

    http://wbyoko.co/angularjs/angularjs-google-maps-components.html

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2013-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      相关资源
      最近更新 更多