![](/img/trans.png)
[英]get the coordinates(latitude and longitude) of google map by street address - angular
[英]get address and zipcode with longitude and latitude in google map
在谷歌地图API中,我想提取地图中心的纬度和经度,并像邮政编码一样获取那里的地址。 这有可能获得邮政编码吗?
我为此目的使用它
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/
你可以得到邮政编码搜索postal_code
类型:
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");
}
}
据我所知,您已经在这里回答了自己的问题。 “邮政编码”是每个国家/地区使用的邮寄地址标识符的通用名称。 在美国,这是“邮政编码”,在英国是“邮政编码”等。
从您链接的文档中:
postal_code表示用于处理该国家/地区内的邮政邮件的邮政编码。
邮政编码下的字段可能是您要查找的内容,不要让命名约定欺骗您。 Google不必为每个国家/地区的可能变化而对字段进行重命名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.