Autocomplete Address From Google Maps API – Javascript

I was going through finding a solution on how to autocomplete the address (commercial or residential), which is being typed by the user to select the exact address from the dropdown through any API without any spelling mistakes. Here’s a very simple and easy solution:

Autocomplete Address From Google Maps API

I found a good and very easy and short solution of autocompleting addresses through Google Maps API. Here is the small Javascript code which you can easily embed insert into your page or template where you want to implement it.

Assuming that you have Google API Key and you’re using/loading jQuery in your code, with a text field customer_address.

<script type=”text/javascript” src=””></script>
<script type=”text/javascript” src=””></script>
<input type=”text” id=”customer_address” />
var input = document.getElementById(‘searchTextField’);
var options = {};
var autocomplete = new google.maps.places.Autocomplete($(“#customer_address”)[0], options);
google.maps.event.addListener(autocomplete, ‘place_changed’, function() {
var place = autocomplete.getPlace();

By addding the above lines even into a simple HTML page, you will be able to get the results which you were looking for.

Leave a Reply

Your email address will not be published. Required fields are marked *