小编Rom*_* M.的帖子

使用Google Maps Javascript API V3反向地理编码检索邮政编码

每当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

18
推荐指数
4
解决办法
5万
查看次数