Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 2, 2014 01:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save devdays/de141c4ceab9f9a96b9f to your computer and use it in GitHub Desktop.
Geolocation error function
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