Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Created August 25, 2013 19:54
Show Gist options
  • Select an option

  • Save jswhisperer/6335913 to your computer and use it in GitHub Desktop.

Select an option

Save jswhisperer/6335913 to your computer and use it in GitHub Desktop.
Basic Geolocation API namespaced
var Geo = {};
Geo.positionOptions = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 30000
}
Geo.error = function(positionError) {
var code = positionError.code,
message = positionError.message,
errorCode = {
1: 'permission denied',
2: 'position unavailable',
3: 'timeout'
};
code = errorCode[code];
//console.log(message + ' ' + code)
};
Geo.callback = function(position) {
var latitude = position.coords.latitude,
longitude = position.coords.longitude,
altitude = position.coords.altitude,
altitudeAccuracy = position.coords.altitudeAccuracy,
heading = position.coords.heading,
speed = position.coords.speed,
timestamp = position.timestamp;
//console.log(position);
};
Geo.get_location = function() {
navigator.geolocation.getCurrentPosition(Geo.callback, Geo.error, Geo.positionOptions);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment