Auto Searching For Places using – Google Maps JavaScript API v3 – Places Autocomplete

Let's say you want your website visitors to be able to complete a form including their location , a feature I need in a current project. 

Here's how to do it using Google's Maps API


    <!-- Google Maps API Stuff -->
        
        <script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>
        <script type="text/javascript">
           function initialize() {
              var input = document.getElementById('location_field');
              var autocomplete = new google.maps.places.Autocomplete(input);
            }
           
           google.maps.event.addDomListener(window, 'load', initialize);
           
        </script>        
        
        <!-- Ends Google Maps API Stuff -->
<form> 
 Location: <input type="text" id="location_field" name="location_field" />
 </form>


Advertisements
Posted in Google Maps API
6 comments on “Auto Searching For Places using – Google Maps JavaScript API v3 – Places Autocomplete
  1. PV says:

    How can I used this on wordpress?

  2. frank says:

    i would like to use on WordPress with contact form 7 , can you give us more details how to use it on wordpress , i added google script to footer.php and form on one of the pages and doesn’t work, after location doesn’t populate with an address, Thank you.

  3. Nikko says:

    Thanks a lot, it worked on my end.

  4. instergo says:

    doesnt work…

    • lancasterdude says:

      Hi, The clue why this doesn’t work may be in the date of the post. Haven’t looked at this in a few years. You may want to RTFM the google maps api docs. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: