Jump to content

alert user if he block gps


khan.sikki

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...