khan.sikki Posted September 2, 2019 Share Posted September 2, 2019 Hello frns, i learnt how to get the gps coordinates from w3school tutorials but a small question how to alter the user if he blocks the gps access request through code <script> var x = document.getElementById("gpsloc"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition, showError); } else { x.value = "Geolocation is not supported by this device."; } } function showPosition(position) { x.value = position.coords.latitude + "," + position.coords.longitude; } function showError(error) { switch(error.code) { case error.PERMISSION_DENIED: x.value = "User denied the request for Geolocation." break; case error.POSITION_UNAVAILABLE: x.value = "Location information is unavailable." break; case error.TIMEOUT: x.value = "The request to get user location timed out." break; case error.UNKNOWN_ERROR: x.value = "An unknown error occurred." break; } } </script> what i want to make is page should check the state of permission and if permission is denied page should alert or keep re-request permission to allow please assist Link to comment Share on other sites More sharing options...
justsomeguy Posted September 3, 2019 Share Posted September 3, 2019 You can do whatever you want to do in the showError function, it will get called if there's an error. Link to comment Share on other sites More sharing options...
khan.sikki Posted September 8, 2019 Author Share Posted September 8, 2019 if user don't know how to allow the permission hence i thought showing permission twice will be a good idea i know how to alert but don't know how to show permission request warm regards, Sikandar Link to comment Share on other sites More sharing options...
justsomeguy Posted September 9, 2019 Share Posted September 9, 2019 I assume you just call getCurrentPosition again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now