Last active
January 26, 2022 18:51
-
-
Save homestar9/b5b12ab457a6a5ce92dc379ea77f50f3 to your computer and use it in GitHub Desktop.
Geolocation Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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