试图遍历谷歌地图地址组件

时间:2013-03-19 14:34:24

标签: jquery google-maps-api-3

为什么这不起作用?我无法遍历从谷歌地图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);

                    }
    });
}
 }

0 个答案:

没有答案