Is there any alternative to navigator.permissions.query Permissions API?

Shiv Kumar Baghel picture Shiv Kumar Baghel · Oct 12, 2018 · Viewed 9.9k times · Source

Is there any alternative to navigator.permissions.query Permissions API query to check geolocation permission. cause its still in Working Draft and has less Browser compatibility.

W3C Permissions Ref : https://www.w3.org/TR/permissions/

Issue is app resume once user perform action on native permission popup then wanted to check the action being taken by user.

Hybrid Cordova App callback for location permission alert

Platform : Mobile Android

NOTE : Don't want to use cordova diagnostic plugin

Example:

navigator.permissions.query({name:'geolocation'}).then(function(result) {

  console.log('result : ', result);

});

Answer

kafinsalim picture kafinsalim · May 13, 2020

You can directly use navigator.geolocation without asking permission first. it will automatically raise ask location prompt like the navigator.permissions do.

navigator.geolocation.getCurrentPosition(
  (i)=>console.log('success',i),
  (i)=>console.log('failed',i)
)

navigator.permissions is not supported in safari and edge, but navigator.geolocation is supported, so i think it's safe to just execute geolocation without checking permission because it also will raise prompt permission first.