Autocomplete location in text box from Google MAP

Expert User Verified

Autocomplete location using a Google API key

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&key=Your API KEY&libraries=places&language=en-AU"></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 address = place.formatted_address;
            

        });
    });
</script>
 <div class="form-group">
    <input type="text" placeholder="google map" name="Location" id="Location"/>
</div>

Location can be autocompleted in textbox using google map API. We have to first create the API Key of google map from Google API cloud by creating your ID.

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&key=Your API KEY&libraries=places&language=en-AU"></script>

Put your API key on the above script.

Please find the rest of the source code right side.

References and Credits

Comments

Leave a Comment