Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you trying to split out the address components?</p> <p>Like street, city, state, zip....</p> <p>If so...you'll want to look at the geocoded result, and parse through the array of address types that it returns.</p> <p>Here is some quick sample code you can use...</p> <pre><code>//Startup a new geocode instance var geocoder = new google.maps.Geocoder(); //event.latLng is a latLng object passed into the geocode function to get your addy results geocoder.geocode({'location': event.latLng}, function(results, status) { //Show the results here console.log(results); if (status == google.maps.GeocoderStatus.OK) { var addressResults = results[0].address_components; var address1 = ""; var address2 = ""; var city = ""; var state = ""; var zipCode = ""; for(var i = 0; i &lt; addressResults.length; i++){ for(var j = 0; j &lt; addressResults[i].types.length; j++){ if(addressResults[i].types[j] == 'street_number'){ address1 = addressResults[i].long_name; break; } if(addressResults[i].types[j] == 'route'){ address1 += " " + addressResults[i].long_name; break; } if(addressResults[i].types[j] == 'subpremise'){ address2 = addressResults[i].long_name; break; } if(addressResults[i].types[j] == 'locality'){ city = addressResults[i].long_name; break; } if(addressResults[i].types[j] == 'administrative_area_level_1'){ state = addressResults[i].short_name; break; } if(addressResults[i].types[j] == 'postal_code'){ zipCode = addressResults[i].long_name; break; } } } //Do ajax post to your form here with the data you just parsed out } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload