Created
March 15, 2011 19:16
-
-
Save alkema/871263 to your computer and use it in GitHub Desktop.
grab lat + lng from js, geocode and then fill in input as formatted address
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
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script> | |
var geocoder = new google.maps.Geocoder(); | |
function success(position) { | |
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); | |
geocoder.geocode({'latLng' : latlng}, function(results, status){ | |
$('#saddr').val(results[0].formatted_address); | |
}); | |
} | |
function error(msg) { | |
var s = document.querySelector('#status'); | |
s.innerHTML = typeof msg == 'string' ? msg : "failed"; | |
s.className = 'fail'; | |
// console.log(arguments); | |
} | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(success, error); | |
} else { | |
error('not supported'); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment