Having problems getting the different arrays content from geocoder results.
item.formatted_address works but not item.address_components.locality?
ge
tried a couple of different requests:
MK107BX
Cleveland Park Crescent, UK
like you say, array size returned is inconsistent but the Town for both results appears to be in the address_component item with type of [ "locality", "political" ]. Perhaps you could use that as an indicator?
EDIT: get the locality object using jQuery, add this to your response function:
var arrAddress = item.results[0].address_components;
// iterate through address_component array
$.each(arrAddress, function (i, address_component) {
if (address_component.types[0] == "locality") // locality type
console.log(address_component.long_name); // here's your town name
return false; // break the loop
});