【发布时间】:2019-03-05 16:49:07
【问题描述】:
查找邮政编码 |邮政编码使用谷歌地图地理编码反向。
我想要这个功能。请检查屏幕截图。
我只想使用 google api 地理编码获取 ewspective google 位置的 pincode
【问题讨论】:
-
请发布您尝试编写的代码。
标签: javascript php reverse-geocoding google-geocoding-api
查找邮政编码 |邮政编码使用谷歌地图地理编码反向。
我想要这个功能。请检查屏幕截图。
我只想使用 google api 地理编码获取 ewspective google 位置的 pincode
【问题讨论】:
标签: javascript php reverse-geocoding google-geocoding-api
function callZipAPI(addSearchZip){
var geocoder = new google.maps.Geocoder();
var zipCode = null;
geocoder.geocode({ 'address': addSearchZip }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//var latitude = results[0].geometry.location.lat();
//var longitude = results[0].geometry.location.lng();
var addressComponent = results[0].address_components;
for (var x = 0 ; x < addressComponent.length; x++) {
var chk = addressComponent[x];
if (chk.types[0] == 'postal_code') {
zipCode = chk.long_name;
}
}
if (zipCode) {
alert(zipCode);
}
else {
alert('No result found!!');
}
} else {
alert('Enter proper address!!');
}
});}
【讨论】: