【问题标题】:Find Postal Code | Zipcode using Google map geocoding reverse查找邮政编码 |使用谷歌地图地理编码反向的邮政编码
【发布时间】:2019-03-05 16:49:07
【问题描述】:

查找邮政编码 |邮政编码使用谷歌地图地理编码反向。

我想要这个功能。请检查屏幕截图。

https://snag.gy/IAaZmr.jpg

我只想使用 google api 地理编码获取 ewspective google 位置的 pincode

【问题讨论】:

  • 请发布您尝试编写的代码。

标签: javascript php reverse-geocoding google-geocoding-api


【解决方案1】:
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!!');
    }
});}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    相关资源
    最近更新 更多