Skip to content

Instantly share code, notes, and snippets.

@homestar9
Last active January 26, 2022 18:51
Show Gist options
  • Save homestar9/b5b12ab457a6a5ce92dc379ea77f50f3 to your computer and use it in GitHub Desktop.
Save homestar9/b5b12ab457a6a5ce92dc379ea77f50f3 to your computer and use it in GitHub Desktop.
Geolocation Javascript
// default center position
var pos = {lat: 37.751918, lng: -122.450249};
if (navigator.geolocation) {
var options = {
//enableHighAccuracy: false,
timeout: 30000, // 30 seconds
maximumAge: 600000 // 10 minutes
};
navigator.geolocation.getCurrentPosition(function(position) {
// populate position with their actual coords
pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
}, function(error) {
// unable to get location
// options
}, options);
} else {
// Browser doesn't support Geolocation
console.log('unable to get location');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment