Request location coordinates after user has blocked access in javascript

23,584

Solution 1

As mentioned by @matthew-shwery, you can not change the permission.
the best you could do is check for the permission and notify the user is the permission is denied

navigator.permissions.query({
     name: 'geolocation'
 }).then(function(result) {
     if (result.state == 'granted') {
         report(result.state);
         geoBtn.style.display = 'none';
     } else if (result.state == 'prompt') {
         report(result.state);
         geoBtn.style.display = 'none';

         navigator.geolocation.getCurrentPosition(revealPosition, positionDenied, geoSettings);
     } else if (result.state == 'denied') {
         report(result.state);
         geoBtn.style.display = 'inline';
     }
     result.onchange = function() {
         report(result.state);
     }
 });

Geolocation docs

Solution 2

You can't.

The user must manage their browser settings manually because your site is added to a blacklist when denied location permissions.

Here are instructions for Chrome users to manage their location permissions: https://support.google.com/chrome/answer/142065?hl=en

Share:
23,584
d-_-b
Author by

d-_-b

(your about me is currently blank)

Updated on July 05, 2022

Comments

  • d-_-b
    d-_-b almost 2 years

    How can I prompt a user for their geo-location in javascript if they've blocked my request in the past? (using navigator.geolocation.getCurrentPosition).

    For example, my web app requires location services, and the user accidentally clicks "block", or they change their mind. What can I do to prompt them again?

  • ToolmakerSteve
    ToolmakerSteve over 4 years
    On Chrome, you can direct them to their settings page: chrome://settings/content/location.
  • ToolmakerSteve
    ToolmakerSteve over 4 years
    On Chrome, you can direct them to their settings page: chrome://settings/content/location.
  • DHRUV GAJWA
    DHRUV GAJWA almost 4 years
    I tried, can use window.open('chrome://settings/content/location"), gives error -> Not allowed to load local resource: chrome://settings/content/location
  • Fernando Torres
    Fernando Torres about 3 years
    how you do that? @ToolmakerSteve
  • ToolmakerSteve
    ToolmakerSteve about 3 years
    @FernandoTorres - what I gave is a URL. What you do with it depends on your situation. You might put it in a link on your page, with some text explaining what this link is, and what to do when they get there.