0

It seems the default behavior for:

navigator.geolocation.getCurrentPosition((position) => {
  // doSomethingWithPoistion
})

makes it so if it's denied. It is denied for all subsequent calls. Is there a way so that when the user hits block on the popup, it's only for this immediate interaction?

That is to say I'm using location services on load of a page. I also have a button that prompts the same functionality. The button doesn't work if the user denies locations services(just get another error callback).

Is there a way to make it so on load denials are only for this callback and doesn't set it to continue to deny on subsequent getCurrentPosition calls?

Andrew Kim
  • 3,145
  • 4
  • 22
  • 42
  • Possible duplicate of [ask for geolocation permission again if it was denied](https://stackoverflow.com/questions/20678707/ask-for-geolocation-permission-again-if-it-was-denied) – rickjerrity Aug 14 '18 at 19:13

1 Answers1

0

From what I can tell when reenacting this in the Chrome browser, it is not so much the denying of the Geolocation call, but the blocking of the geolocation call.

When running the code snippet you provided in Chrome, when simply escaping out of the permission pop-up by hitting the X button, I am able to trigger the permission prompt every time the code is ran. If I hit the Block button to close the permission pop-up, the website is added to my list of blocked sites in Chrome and never asks for permission again.

This solution linked below seems to be one of the better ways to handle this situation. It recommends that you check the current state of the geolocation permission, and notify the user if it is currently denied.

https://stackoverflow.com/a/42476603/6121503

rickjerrity
  • 804
  • 1
  • 9
  • 15