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 : /
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);
});
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);
});
Share
Improve this question
edited Oct 16, 2018 at 2:16
Shiv Kumar Baghel
asked Oct 12, 2018 at 17:34
Shiv Kumar BaghelShiv Kumar Baghel
2,4806 gold badges19 silver badges35 bronze badges
10
|
Show 5 more comments
2 Answers
Reset to default 9You 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.
I don't think so.
At this moment the navigator.permissions object is undefined - probably it's removed in WebView by purpose to not mix web permissions with android permissions.
Option 1:
You may try Cordova diagnostic plugin, specifically the getLocationAuthorizationStatus
method which should return permission state in very similar way to Permissions API.
Please note I haven't tried the plugin.
Option 2:
Trigger location permissions dialog by requesting location.
When you'll receive PositionError with PERMISSION_DENIED
constant code, it'll mean that user denied location permission (just now or at app settings).
navigator.getCurrentPosition(
function(position) { /** won't be executed for such short timeout */ },
function(positionError) {
switch (positionError.code) {
// PERMISSION_DENIED
case 1:
console.log('Permission denied')
break
// POSITION_UNAVAILABLE
case 2:
console.log('Permission allowed, location disabled')
break
// TIMEOUT
case 3:
console.log('Permission allowed, timeout reached')
break
}
},
{timeout: 0}
)
name
? – Jaromanda X Commented Oct 12, 2018 at 17:56geolocation
permission. – Shiv Kumar Baghel Commented Oct 12, 2018 at 18:01