I've been trying to figure this out for so long that I'm sure it's staring me in the face.
I'm using jquery to auto complete an address being entered by a user with the following code:
$(function() {
$("#address").autocomplete({
//This bit uses the geocoder to fetch address values
source : function(request, response) {
geocoder.geocode({'address' : request.term },
function(results, status) {
response($.map(results, function(item) {
return {
label : item.formatted_address,
value : item.formatted_address,
latitude : item.geometry.location.lat(),
longitude : item.geometry.location.lng(),
streetNo : item.address_components[0].long_name,
streetName : item.address_components[1].long_name,
town : item.address_components[2].long_name,
province : item.address_components[4].long_name,
}
}));
})
}
I need to extract the address components specfically i.e. postal code. Right now I'm using numbers but depending on the address inputted, the fields may or may not be correct.
I pretty much have the same question this guy did:
Google Maps Geocoder: Return postal_code
The answer to that question is appropriate but the issue I"m having his when I try to loop, or do anything other than extract the info the way it's already done here the script fails.
Based on the way the jquery autocomplete does it's google query, can I assign the "results" to a variable and then parse it that way for correct type names?
Everything I've tried so far has failed, usually resulting in the script not running.
I'm getting desperate here, hopefully my question is coherent! :P