Skip to content

Instantly share code, notes, and snippets.

@restureese
Created February 15, 2021 12:22
Show Gist options
  • Select an option

  • Save restureese/8a0da866dba6d79f455015a63a0afa85 to your computer and use it in GitHub Desktop.

Select an option

Save restureese/8a0da866dba6d79f455015a63a0afa85 to your computer and use it in GitHub Desktop.
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition,showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
localStorage.setItem("lat", position.coords.latitude);
localStorage.setItem("lng", position.coords.longitude);
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
showNotifError("Lokasi belum di setujui")
break;
case error.POSITION_UNAVAILABLE:
showNotifError("Lokasi tidak tersedia")
break;
case error.TIMEOUT:
showNotifError("Request time out")
break;
case error.UNKNOWN_ERROR:
showNotifError("An unknown error occurred.")
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment