每当googlemaps视口中心发生变化时,我都会尝试使用邮政编码向我的数据库提交查询.我知道这可以通过反向地理编码完成,例如:
google.maps.event.addListener(map, 'center_changed', function(){
newCenter();
});
...
function newCenter(){
var newc = map.getCenter();
geocoder.geocode({'latLng': newc}, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
var newzip = results[0].address_components['postal_code'];
}
});
};
Run Code Online (Sandbox Code Playgroud)
当然,这段代码实际上并不起作用.所以我想知道如何更改这个以便从结果数组中提取邮政编码.谢谢
google-maps geocoding postal-code reverse-geocoding google-maps-api-3