I am geocoding the address using google map APIs and I need to get street address, city, state and zip code in different fields. Based on the documentation of the types of address components that are returned as a result, this is my code:
var address = ""; var city = ""; var state = ""; var zip = ""; geocoder.geocode( { 'address': inputAddress}, function(results, status){ if (status==google.maps.GeocoderStatus.OK){ // loop through to get address, city, state, zip $.each(results[0].address_components, function(){ switch(this.types[0]){ case "postal_code": zip = this.short_name; break; case "street_address": address = this.short_name; break; case "administrative_area_level_1": state = this.short_name; break; case "locality": city = this.short_name; break; } }); } else{ alert("Invalid Address"); } });
However, it seems that when I entered the addresses, "street_address" does not return; instead, it is returned as separate fields, most often "street_number" and "route", sometimes additional fields (for example, "subpremise" for apt number). See this sample geocoding result in documents.
How can I get an address variable that contains any fields associated with a street address? For example, in the docs I would like the 1600 Ampitheater Parkway.
parsing google-maps-api-3 geocoding
froadie
source share