Geolocation error function
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
function getLocation() { | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(showPosition, | |
errorFunction); | |
} else { | |
loc.innerHTML = "Geolocation is not supported by this browser."; | |
} | |
} | |
function showPosition(position) { | |
loc.innerHTML = "Latitude: " + position.coords.latitude + | |
"<br>Longitude: " + position.coords.longitude; | |
} | |
function errorFunction(error) { | |
switch (error.code) { | |
case error.PERMISSION_DENIED: | |
loc.innerHTML = "User denied the request for Geolocation." | |
break; | |
case error.POSITION_UNAVAILABLE: | |
loc.innerHTML = "Location information is unavailable." | |
break; | |
case error.TIMEOUT: | |
loc.innerHTML = "The request to get user location timed out." | |
break; | |
case error.UNKNOWN_ERROR: | |
loc.innerHTML = "An unknown error occurred." | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment