igorpreston / ember-cli-geo

Geolocation service for Ember.js web apps
MIT License
50 stars 16 forks source link

Gracefully handling user rejection of get location #16

Closed bmfay closed 6 years ago

bmfay commented 6 years ago

Does this service expose any way to see whether the user has blocked the geo location? As far as I can tell, the promise just never resolves. I'd like to be able to provide a UX where we can display a message to our users explaining that the feature they are trying to use will not work if they block geolocation. Thanks.

ezy commented 6 years ago

You can use navigator.permissions.query to check state before actioning your geoLocation() call. Would be nice for this feature to be baked in though with it's own API functions.

navigator.permissions.query({name: 'geolocation'}).then((result) => {
        console.log(result);
        if (result.state === 'granted') {
          console.log('Permission ' + result.state);
        }
        else if (result.state === 'prompt') {
          console.log('Permission ' + result.state);
          this.send('checkinEnable');
        }
        else if (result.state === 'denied') {
          console.log('Permission ' + result.state);
        }
        result.onchange = function() {
          console.log('Permission ' + result.state);
        };
      });
bmfay commented 6 years ago

Thanks @ezy. For unrelated reasons we no longer need geolocation in our app, but that looks like it will do the trick if I need this behavior in the future. Thanks!