在Google地图中获取具有经度和纬度的地址和邮政编码 [英] get address and zipcode with longitude and latitude in google map
本文介绍了在Google地图中获取具有经度和纬度的地址和邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在google map api中,我想提取地图中心的经度和纬度,并像邮政编码一样获取那里的地址.
可以获取邮政编码吗?
我为此目的使用了
in google map api, i want to extract map center latitude and longitude and get address of there like a zipcode.
this is possible to get zipcode ?
i use this for this purpose
var lat = -24.448674;
var lng = 135.684569;
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[1]) {
alert(results[1].formatted_address);
} else {
alert("No results found");
}
}
else
{
alert("Geocoder failed due to: " + status);
}
});
但是在上面的代码中,我无法获取邮政编码和邮政编码!
https://developers.google.com/maps/documentation/geocoding/ >
but in above code i can't get zipcode and get postal code!
https://developers.google.com/maps/documentation/geocoding/
推荐答案
您可以获得搜索postal_code
类型的邮政编码:
You can get postal code searching for postal_code
type:
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
for (var i = 0; i < results[0].address_components.length; i++) {
var types = results[0].address_components[i].types;
for (var typeIdx = 0; typeIdx < types.length; typeIdx++) {
if (types[typeIdx] == 'postal_code') {
//console.log(results[0].address_components[i].long_name);
console.log(results[0].address_components[i].short_name);
}
}
}
} else {
console.log("No results found");
}
}
这篇关于在Google地图中获取具有经度和纬度的地址和邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文