Jump to content
Sign in to follow this  
khan.sikki

alert user if he block gps

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 

Share this post


Link to post
Share on other sites

You can do whatever you want to do in the showError function, it will get called if there's an error.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...