angularJS使用angular谷歌地图查找位置/地名

angularJS find the location/place name using angular google map

本文关键字:位置 地名 查找 谷歌地图 使用 angular angularJS      更新时间:2023-09-26

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

        }
      }
    };

给定纬度/经度对象,您可以使用谷歌地图API将位置映射到近似地址。您可以使用Geocoding API将位置映射到地址,将地址映射到位置。

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

Google Map API for Geocoding.

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

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

Geocoder。geocode({'latLng': latLngObject}, callback);

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

希望有帮助!!