Last active
August 29, 2015 13:56
-
-
Save Mark-Broadhurst/8843832 to your computer and use it in GitHub Desktop.
Google Location API Example
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> | |
<title>Google Location API Example</title> | |
<script type='text/javascript' src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script> | |
</head> | |
<body> | |
<label for='search'>Search:</label> | |
<input id='search' type='text' /> | |
<br/> | |
<label for='lat'>Lat:</label> | |
<input id='lat' type='text' /> | |
<br/> | |
<label for='long'>Long:</label> | |
<input id='lng' type='text' /> | |
<br/> | |
<textarea id='address'></textarea> | |
<script type='text/javascript' src="lookup.js"></script> | |
</body> | |
</html> |
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
var options = { | |
types: ['geocode'], | |
componentRestrictions: { | |
country: 'uk' | |
} | |
}; | |
var element = document.getElementById('search'); | |
var autocomplete = new google.maps.places.Autocomplete(element, options); | |
google.maps.event.addListener(autocomplete, 'place_changed', function () { | |
var result = autocomplete.getPlace(); | |
document.getElementById('address').value = result.formatted_address; | |
document.getElementById('lat').value = result.geometry.location.lat(); | |
document.getElementById('lng').value = result.geometry.location.lng(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment