javascript angularJS 使用 angular google map 查找位置/地名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31870479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
angularJS find the location/place name using angular google map
提问by RIYAJ KHAN
I want to find the location name
which user select on map.
Currently I am getting latitude and longitude both.
But unable to get the location name.
我想找到location name
哪个用户在地图上选择。目前我同时获得纬度和经度。但无法获取位置名称。
I am using angularJS
and angular-google-maps 2.1.5.
我正在使用angularJS
和 angular-google-maps 2.1.5.
Here is the html.
这是html。
<ui-gmap-google-map center="map.center" zoom="map.zoom" draggable="true" options="options" events="map.events">
</ui-gmap-google-map>
JS :
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
};
Anything is appreciated.
任何事情都值得赞赏。
回答by RIYAJ KHAN
Here what I have done using 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);
}
});
}
}
};
回答by Raj Kantaria
Given Latitude/Longitude object you can map location to approximate address using Google Map API. You can use the Geocoding API for mapping locations to addresses and addresses to locations.
给定纬度/经度对象,您可以使用 Google Map API 将位置映射到近似地址。您可以使用地理编码 API 将位置映射到地址以及将地址映射到位置。
Geocoder.geocode( { 'latLng': latLngObject }, callbackFn);
Hereis the link for Google Map API for Geocoding.
这是用于地理编码的 Google Map API 的链接。
回答by Megha Nagpal
Try these links https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse?csw=1
试试这些链接 https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse?csw=1
Use the Geocoding API for mapping locations to addresses and addresses to locations. http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
使用地理编码 API 将位置映射到地址以及将地址映射到位置。http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding
Geocoder.geocode( { 'latLng': latLngObject }, callback);
Geocoder.geocode( { 'latLng': latLngObject }, 回调);
http://wbyoko.co/angularjs/angularjs-google-maps-components.html
http://wbyoko.co/angularjs/angularjs-google-maps-components.html
Hope it helps!!!
希望能帮助到你!!!