Created
August 13, 2020 02:24
-
-
Save jstott/cbf524452ad1ee593c1657faa00457f2 to your computer and use it in GitHub Desktop.
Detect User's Current Location Using HTML5 Geolocation
This file contains 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
// 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