Skip to content

Instantly share code, notes, and snippets.

@mislav
Created September 18, 2009 08:51
Show Gist options
  • Save mislav/188952 to your computer and use it in GitHub Desktop.
Save mislav/188952 to your computer and use it in GitHub Desktop.
Geolocate users with modern browsers (or with Google Gears)
var geo = navigator.geolocation || (window.google && google.gears && google.gears.factory.create('beta.geolocation'));
if (geo) geo.getCurrentPosition(displayLocation, handleError);
function displayLocation(position) {
position.coords.latitude;
position.coords.longitude;
position.coords.accuracy;
}
function handleError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert('Sorry. Permission to find your location has been denied.');
break;
case error.POSITION_UNAVAILABLE:
alert('Sorry. Position unavailable.');
break;
default:
alert('Error code: ' + error.code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment