Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Auto Complete Location and Get Longitude and Latitude using Google Map API
<!DOCTYPE html>
<script src=""></script>
<label for="locationTextField">Location</label>
<input id="locationTextField" type="text" size="50">
<div id="output" />
function init() {
var input = document.getElementById('locationTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
google.maps.event.addListener(autocomplete, 'place_changed',
function() {
var place = autocomplete.getPlace();
var lat =;
var lng = place.geometry.location.lng();
document.getElementById("output").innerHTML = "Lat: "+lat+"<br />Lng: "+lng;
google.maps.event.addDomListener(window, 'load', init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment