为什么这不起作用?我无法遍历从谷歌地图api返回的地址组件。
if (geocoder) {
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var arrAddress = results[0].address_components;
console.log(arrAddress);
//iterate through address_component array
$.each(arrAddress, function (i, address_component) {
console.log('address_component:'+i);
if (address_component.types[0] == "locality"){
console.log("town:"+address_component.long_name);
}
});
}
}