Skip to content

Instantly share code, notes, and snippets.

@jstott
Created August 13, 2020 02:24
Show Gist options
  • Save jstott/cbf524452ad1ee593c1657faa00457f2 to your computer and use it in GitHub Desktop.
Save jstott/cbf524452ad1ee593c1657faa00457f2 to your computer and use it in GitHub Desktop.
Detect User's Current Location Using HTML5 Geolocation
// Since this can compromise privacy, the position is not available unless the user approves it.
function get_location() {
try {
navigator.geolocation.watchPosition((pos) => {
try {
var coords = pos.coords;
} catch {
var coords = false;
}
if (!coords) {
vueModel.coords = false;
} else {
vueModel.coords = coords;
}
});
} catch (e) {
vueModel.coords = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment