gpt4 book ai didi

javascript - angularJS 使用 Angular 谷歌地图查找位置/地名

转载 作者:太空宇宙 更新时间:2023-11-04 13:34:35 28 4
gpt4 key购买 nike

我想找到用户在 map 上选择的位置名称。目前我正在获取纬度和经度。但无法获取位置名称。

我正在使用 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
};

不胜感激。

最佳答案

这是我使用 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);
}
});


}
}
};

关于javascript - angularJS 使用 Angular 谷歌地图查找位置/地名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31870479/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com