Last active
June 6, 2017 19:38
-
-
Save jon-kim/3c4f71db4e65538d5896c0267bc225a2 to your computer and use it in GitHub Desktop.
Auto Complete Location and Get Longitude and Latitude using Google Map API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script> | |
</head> | |
<body> | |
<label for="locationTextField">Location</label> | |
<input id="locationTextField" type="text" size="50"> | |
<div id="output" /> | |
<script> | |
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 = place.geometry.location.lat(); | |
var lng = place.geometry.location.lng(); | |
document.getElementById("output").innerHTML = "Lat: "+lat+"<br />Lng: "+lng; | |
} | |
); | |
} | |
google.maps.event.addDomListener(window, 'load', init); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment