Jump to content

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 

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."
      x.value = "Location information is unavailable."
    case error.TIMEOUT:
      x.value = "The request to get user location timed out."
    case error.UNKNOWN_ERROR:
      x.value = "An unknown error occurred."

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

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...