Created
February 15, 2021 12:22
-
-
Save restureese/8a0da866dba6d79f455015a63a0afa85 to your computer and use it in GitHub Desktop.
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
| 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