[FEATURE] geolocation permission
See original GitHub issueš Feature request
Is your feature request related to a problem?
Having GEOLOCATION_SUPPORT
injection token does not quite answer the question of whether the developer can use the geolocation Web API. The GEOLOCATION_SUPPORT
simply checks if navigator.geolocation
object is available. However, the user may have received the browser popup during one of the previous visits to the website and automatically clicked āBlockā (like many of us do these days whenever any popup shows up). In this case, the GEOLOCATION_SUPPORT
will resolve to true, but geolocation$
observable will emit an error.
Describe the solution youād like
To answer the question of whether the user has allowed the website access to geolocation, we can run the following code:
navigator.permissions.query({ name: 'geolocation' }).then((x) => console.log(x.state))
// this will print "prompt", "denied", or "granted"
I wonder if an injection token GEOLOCATION_PERMISSION
could be introduced that would run the code above under the hood? Given the fact that this API returns a Promise
, Iām not sure if it can still be an Injection token or if itāll have to be an observable service similar to the geolocation$
[Important] Something to keep in mind: the support for the API above is somewhat spotty: https://caniuse.com/permissions-api
Describe alternatives youāve considered
Here people suggest using the second callback for the navigator.geolocation.watchPosition
method thatās called upon an error. This does not really solve the issue for me because calling this function will trigger the popup and I would like to know whether the geolocation Web API is available before the popup shows up.
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (7 by maintainers)
Top GitHub Comments
I think we have to move up to Angular 9. Tomorrow Angular 8 LTS will end https://angular.io/guide/releases#support-policy-and-schedule
Created a PR for this: https://github.com/ng-web-apis/permissions/pull/1 Iām closing this issue. Letās move our conversation into the PR.