Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Find user location with GPS
// adapted and simplified from
// https://developers.google.com/web/fundamentals/native-hardware/user-location/obtain-location
// find location
window.onload = function() {
var geoOptions = {
timeout: 10000, // milliseconds
maximumAge: 5 * 60 * 1000 // milliseconds
}
var geoSuccess = function(position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
};
var geoError = function(error) {
console.log('Error occurred. Error code: ' + error.code);
// error.code can be:
// 0: unknown error
// 1: permission denied
// 2: position unavailable (error response from location provider)
// 3: timed out
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geoSuccess, geoError, geoOptions);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment