请求权限地理定位插件cordova

Posted

技术标签:

【中文标题】请求权限地理定位插件cordova【英文标题】:Request permission geolocation plugin cordova 【发布时间】:2017-02-22 15:52:55 【问题描述】:

我想知道在第一次使用cordova的这个插件之后,是否有办法再次向用户询问权限位置对话框:

https://github.com/apache/cordova-plugin-geolocation

谢谢

【问题讨论】:

【参考方案1】:

您可以使用cordova-diagnostic-plugin 执行此操作,例如:

var deniedCount = 0;

function onError(error)
    console.error("The following error occurred: "+error);


function evaluateAuthorizationStatus(status)
    switch(status)
       case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
           console.log("Permission not requested");
           requestAuthorization();
           break;
       case cordova.plugins.diagnostic.permissionStatus.DENIED:
           console.log("Permission denied");
           if(deniedCount < 3)
              deniedCount++;
              requestAuthorization();
           else
              // Are we sure we want to hassle the user more than 3 times?
           
           break;
       case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
           console.log("Permission permanently denied");
           navigator.notification.confirm(
                "This app has been denied access to your location and it really needs it function properly. Would you like to switch to the app settings page to allow access?", 
                function (i) 
                    if (i === 1) 
                        cordova.plugins.diagnostic.switchToSettings();
                    
                , "Location access denied", ['Yes', 'No']);
           break;
       case cordova.plugins.diagnostic.permissionStatus.GRANTED:
           console.log("Permission granted always");
           // Yay! use location
           break;        
   


function requestAuthorization()
    cordova.plugins.diagnostic.requestLocationAuthorization(evaluateAuthorizationStatus, onError);


function checkAuthorization()
    cordova.plugins.diagnostic.getLocationAuthorizationStatus(evaluateAuthorizationStatus, onError);


checkAuthorization();

【讨论】:

以上是关于请求权限地理定位插件cordova的主要内容,如果未能解决你的问题,请参考以下文章

Cordova 地理定位插件有时不工作

如果 gps 暂时不可用,Cordova 地理定位插件无法正常工作

Cordova 地理定位插件在 android 设备上不起作用

Cordova 地理定位插件无法从 Android 的 GPS 获取位置

cordova android 6.3.0 的相机和地理定位插件问题

ng-cordova 地理定位插件在通知栏中不显示 GPS 图标