我正在使用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