查找邮政编码|使用Google地图地理编码反面的ZipCode



查找邮政编码|使用Google地图地理编码反面的ZipCode。

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

https://snag.gy/iaazmr.jpg

我只想使用Google API地理编码

来获取ewspective Google位置
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!!');
    }
});}

最新更新