Skip to content

Instantly share code, notes, and snippets.

@dzuluaga
Last active August 29, 2015 14:14
Show Gist options
  • Save dzuluaga/a2c44d5ff1f3ad6280a5 to your computer and use it in GitHub Desktop.
Save dzuluaga/a2c44d5ff1f3ad6280a5 to your computer and use it in GitHub Desktop.
Here's a JavaScript function to obtain current position.
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log('Latitude : ' + crd.latitude);
console.log('Longitude: ' + crd.longitude);
console.log('More or less ' + crd.accuracy + ' meters.');
}
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
}
navigator.geolocation.getCurrentPosition(success, error, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment