javascripthtmlw3c-geolocation

Is there a way to check if geolocation has been DECLINED with Javascript?


I need JavaScript to display a manual entry if geolocation is declined.

What I have tried:

Modernizr.geolocation
navigator.geolocation

Neither describes if user has previously declined access to geolocation.


Solution

  • Without prompting the user, you can use the new permission api this is available as such:

    navigator.permissions.query({ name: 'geolocation' })
    .then(console.log)