Geocoder Respsone Loop - Cannot Read Property '0' Of Undefined
I am sending a lon/lat to google geocoder and getting a response data that trying to break into variabels, the response look like this: this is my code: getFormattedAddress(resul
Solution 1:
var arr = [
{
"long_name": "29-31", "short_name": "29-31",
"types": [ "street_number" ]
},
{
"long_name": "Götgatan", "short_name": "Götgatan",
"types": [ "route" ]
},
{
"long_name": "Södermalm", "short_name": "Södermalm",
"types": [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name": "Stockholm", "short_name": "Stockholm",
"types": [ "locality", "political" ]
},
{
"long_name": "Stockholm", "short_name": "Stockholm",
"types": [ "postal_town" ]
},
{
"long_name": "Stockholms län", "short_name": "Stockholms län",
"types": [ "administrative_area_level_1", "political" ]
},
{
"long_name": "Sverige", "short_name": "SE",
"types": [ "country", "political" ]
},
{
"long_name": "118 26", "short_name": "118 26",
"types": [ "postal_code" ]
}
]
for (var i=0; i< arr.length ; i++) {
if (arr[i].types.indexOf('route') > -1)
console.log( 'route ' + arr[i].long_name );
if (arr[i].types.indexOf('locality') > -1)
console.log( 'locality ' + arr[i].long_name );
}
Post a Comment for "Geocoder Respsone Loop - Cannot Read Property '0' Of Undefined"