Skip to content

Instantly share code, notes, and snippets.

@livingston
Created April 28, 2010 12:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save livingston/382086 to your computer and use it in GitHub Desktop.
Save livingston/382086 to your computer and use it in GitHub Desktop.
HTML5 Geolocation with Fallback to Google Ajax API
<!-- HTML5 Geolocation with Fallback to Google Ajax API
-- http://marcgrabanski.com/article/html5-geolocation-fallback-google-ajax-api
-->
<script src="http://www.google.com/jsapi?key=YOUR_API_KEY" type='text/javascript'></script>
<script type='text/javascript'>
var myLocation; // global variable to store lat/lng
if (navigator && navigator.geolocation) {
// HTML5 GeoLocation
function getLocation(position) {
myLocation = {
"lat": position.coords.latitude,
"lng": position.coords.longitude
}
}
navigator.geolocation.getCurrentPosition(getLocation);
} else {
// Google AJAX API fallback GeoLocation
if ((typeof google === 'object') && google.loader && google.loader.ClientLocation) {
myLocation = {
"lat": google.loader.ClientLocation.latitude,
"lng": google.loader.ClientLocation.longitude
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment