我正在使用Google地图地理编码器。我有一切工作正常,但我似乎无法弄清楚如何“遍历”(解析?)JSON结果。从JSON结果中获取邮政编码值
如何从Geocoder的JSON结果中获取邮政编码?
我试图循环访问'address_components',为包含“postal_code”的数组测试每个“值”键。
所以这里是什么,我到目前为止已经写了一个片段:
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address : cAddress }, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
var fAddress = results[0].formatted_address;
var contactLatLng = results[0].geometry.location;
var postalCode = $.each(results[0].address_components,
function(componentIndex, componentValue) {
var typesArray = componentValue.types;
if ($.inArray("postal_code", typesArray)) {
return componentValue.long_name;
}
})
}
}
});
的问题特别是postalCode
是
[object Object],[object Object],[object Object],[object Object],
[object Object],[object Object],[object Object]`
显然,有我丢失的东西。
仅供参考,这里是链接到谷歌地图地理编码JSON结果: http://code.google.com/apis/maps/documentation/geocoding/#JSON
感谢您的帮助! 〜阿莫斯
唉唉...... asynchonous是我失踪了。谢谢! – amosglenn