I'm implementing Google Places in a form where the user will enter his/her location. The location can be a full address or just a city.
I want to get each individual component of the address the user has provided. What's the best way to get each component i.e. address, city, state, zip code and country.
In the code below, I'm getting the components which appears to be an array. Do I have to loop through it or is there a direct way for me to access each component?
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('location'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var components = place.address_components;
});
});
</script>