Search code examples
javascriptbrowsergeolocationcompatibility

How to know users location permission without triggering permission popup?


I want to use my user's location to do some actions...

The problem is that I don't want to trigger the GeoLocation API popup in case the user hasn't allowed/blocked it, because he'd be confused why I'm asking for it.

So, navigating to mysite.com/page-that-needs-geolocation, what should happen is:

  1. Redirect the user to another page (mysite.com/why-enable-geolocation) in case he hasn't allowed/blocked the GeoLocation, and ask for the permission there.
  2. Redirect the user to another page (mysite.com/enter-your-position) in case he has blocked the GeoLocation.
  3. Let the user continue on the page (mysite.com/page-that-needs-geolocation), and use his geolocation.

I'm aware of Permission API, but it's super limited to modern browsers and I can't have that.

Is there a different approach to this problem or another API I can use?


Solution

  • This is currently not possible, due to browser limitations.

    Canceling (dismissing) or denying permission will lead to the same result, even though you can re-trigger a new permission request in a new session, if the user dismissed the popup.