Right now I am implementing it through a JS script based on advice from
Google
, but I am trying to figure out how to have the autocomplete fill in multiple fields, like in the example, then fill contact details, like city, state, etc. The manual, from my perspective, is not clear as how to achieve that.
I would appreciate something in the right direction.
Here is the code of the question. It's basic. I've removed my API key for security reasons.
Code:
<p><script src="https://maps.googleapis.com/maps/api/js?key=[APIKEY]&libraries=places"></script><script src="jquery.geocomplete.js"></script>Please enter your address.</p>
<p>powered by Google</p>
<p id="displayCounty"> </p>
<script>
function init() {
$('#displayCounty').hide();
var input = document.getElementById('answer161767X10X131');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
var components = place.address_components;
if (components) {
for (var i = 0, l = components.length; i < l; i++) {
var component = components[i];
if (component.types &&
component.types.indexOf('administrative_area_level_2') !== -1) {
$('#displayCounty').text('County: ' + component.long_name);
$('#displayCounty').show();
}
}
}
});
}
google.maps.event.addDomListener(window, 'load', init);
</script>