Skip to content

Instantly share code, notes, and snippets.

@cjus
Created July 31, 2011 00:20
Show Gist options
  • Save cjus/1116181 to your computer and use it in GitHub Desktop.
Save cjus/1116181 to your computer and use it in GitHub Desktop.
WC3 Geolocation
var options = {
enableHighAccuracy: true,
maximumAge: 60000,
timeout: 0
};
if (window.navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
} else {
alert('Your browser does not natively support geolocation.');
}
function successCallback(position) {
var output = '';
output += "Your position has been located.\n\n";
output += 'Latitude: ' + position.coords.latitude + "\n";
output += 'Longitude: ' + position.coords.longitude + "\n"; output += 'Accuracy: ' + position.coords.accuracy + " meters\n"; if (position.coords.altitude)
output += 'Altitude: ' + position.coords.altitude + " meters\n"; if (position.coords.altitudeAccuracy)
output += 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + " meters\n";
if (position.coords.heading)
output += 'Heading: ' + position.coords.Heading + "\n";
if (position.coords.speed)
output += 'Speed: ' + position.coords.Speed + " m/s\n";
output += 'Time of Position: ' + position.timestamp;
Debugger.log(output);
//alert(output);
}
function errorCallback(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
Debugger.log('You have denied access to your position.');
break;
case error.POSITION_UNAVAILABLE:
Debugger.log('There was a problem getting your position.');
break;
case error.TIMEOUT:
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
Debugger.log('The application has timed out attempting to get your location.');
break;
}
Debugger.log(error.message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment