This is very basic for google address lookup/auto completion tutorial.
First thing you need to do is include google maps javascript to your page.
When user selects an address, value of input field get updated to selected address. You do not need to have nay extra code. However in case if you want to read selected address, you will need to add "place_changed" google maps event listener. It returns PlaceResult object. Following code shows how you can get PlaceResult object.
Here is the complete snippet.
First thing you need to do is include google maps javascript to your page.
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
Next step is to initialize Autocomplete. When you initialize Autocomplete, it basically starts a listener which listens for an input. Following code does that.
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
When you start typeing it looks like this.

When user selects an address, value of input field get updated to selected address. You do not need to have nay extra code. However in case if you want to read selected address, you will need to add "place_changed" google maps event listener. It returns PlaceResult object. Following code shows how you can get PlaceResult object.
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
alert(place.formatted_address);
You can find a demo here: Google Address Auto Complete Demo
In this example, I am loading address lookup form using an ajax.
You can download demo source from github: View source code
Here is the complete snippet.
thanks a lot. I was looking for this indeed
ReplyDeleteHey, it doesent work for me. I put the first four Lines into my Code, but when i type in the SearchField no Autocompletion appears.
ReplyDeletedo you have an advice?
I like your blog content
ReplyDeletewebsite development company in bangalore
what if i want to add a new field into the autocomplete result?
ReplyDeleteNot working for me either.
ReplyDeleteI can tell that the browser is asking google for the results, they are just not being displayed.
Which browser are you trying with? I just tested in chrome http://priyankgandhi.com/googleapi/ And it is working.
ReplyDeleteHow to get Postal Code at end of each address?
ReplyDeleteHey, this isnt working for me. If I place the exact code provided by you, I receive the following error:
ReplyDeleteSyntaxError: missing : after property id
$(function() {
Can you please help?
Excelente Trabajo lo voy a implementar en:
ReplyDeletehttp://calimaframework.com
Podrian ayudarme en esto, http://es.stackoverflow.com/questions/8637/c%C3%B3mo-realizar-autocompletar-en-mi-cuadro-de-b%C3%BAsqueda
ReplyDeletehe tratado de implementar que está en este post pero no logro dar solución.
se los agradecere demasiado.!
Develop strong programming skills using Java to create reliable and platform-independent applications. java training online
ReplyDeleteLearn the fundamentals of creating intuitive, engaging, and user-centered digital designs.ui ux online course
ReplyDeleteGain skills to design data structures that ensure consistency, accuracy, and efficient data management. data modeling courses online
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteLearn how to access and manage digital land records through the Bhoomi land information system. dell boomi full course
ReplyDeletePython training offers in-depth understanding of Python fundamentals and applications. It explains variables, loops, and functions clearly. This python training improves hands-on programming skills. Students build real-world programs. Modules, packages, and standard libraries are included. Web and automation basics are covered. Problem-solving techniques are explained. It prepares industry-ready Python professionals.
ReplyDeleteEnrolling in a servicenow admin course is a smart step for anyone looking to enter the IT service management field. It helps you understand core concepts, platform navigation, and real-time applications with ease.servicenow admin course
ReplyDeleteThis blog clearly explains the value of MuleSoft certification for career growth and professional credibility.mule soft certification
ReplyDeleteA mulesoft developer course helps in building strong skills in API design and implementation.
ReplyDeletemulesoft developer course
This article makes it easier to understand what to expect from ServiceNow classes. Very helpful for beginners.servicenow classes
ReplyDeleteVery informative! data modeling course
ReplyDeleteplays a crucial role in organizing and managing data. Skill-based training helps learners gain confidence in designing accurate and efficient database systems.
A great explanation of servicenow administrator course, covering both basics and career opportunities.servicenow administrator course
ReplyDeleteThe ServiceNow classes mentioned here seem well-organized and practical for gaining real-time experience.servicenow classes
ReplyDeleteServiceNow classes with practical exposure are very important. This blog explains it clearly.servicenow classes
ReplyDeleteServiceNow Classes provide step-by-step guidance on platform navigation, system configuration, and IT workflow management. It is suitable for both beginners and working professionals.servicenow classes
ReplyDeleteExcellent article with valuable information. I learned several new things from this post today. Looking forward to more content from you.online business analyst classes
ReplyDeleteA full stack python developer course helps learners understand frontend and backend web development using Python technologies. It explains databases, frameworks, APIs, and application architecture clearly. This full stack python developer course helps students gain practical experience through real-time projects. Learners develop complete web applications from scratch. The course prepares learners for full stack development careers.
ReplyDelete