Created
April 28, 2010 12:40
-
-
Save livingston/382086 to your computer and use it in GitHub Desktop.
HTML5 Geolocation with Fallback to Google Ajax API
This file contains hidden or 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
<!-- 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