Using the GEOlocation API - https://developers.google.com/web/fundamentals/native-hardware/user-location/
-
-
Save philcon93/638a5e5aed8b38520f21b44f4462d94a to your computer and use it in GitHub Desktop.
geolocation
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
var startPos; | |
var geoSuccess = function(position) { | |
startPos = position; | |
console.log(startPos.coords.latitude); | |
console.log(startPos.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 | |
}; | |
// check for Geolocation support | |
if (navigator.geolocation) { | |
console.log('Geolocation is supported!'); | |
navigator.geolocation.getCurrentPosition(geoSuccess, geoError); | |
} | |
else { | |
console.log('Geolocation is not supported for this Browser/OS.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment