Search code examples
javascriptgeolocation

Tell if user has granted website permanent permission to get location in browser


I am calling navigator.geolocation.getCurrentPosition with no troubles. In my web app I have a more user friendly screen that explains the use of the user's location and they press a button to initiate this request. This is all working lovely jubbly.

However, when a user says "always grant this permission" I want to be able to skip this whole process and just get the location automatically. So, is there a way to do something like:

if (!navigator.geolocation.hasPermission)
    navigator.geolocation.getCurrentPosition(etc, etc);
else
    showMyLovelyReasonsWhy();

Thanks in advance!


Solution

  • Seems like you have to make a workaround for this to happen.

    Please see: Is there a way of detecting whether a user has already given permission to use navigator.geolocation?