当我的应用程序启动时,我会检查本地GPS是否已启用,如果没有,则会弹出一个启用的问题,然后将用户定向到他们必须手动启用的设置页面:
cordova.plugins.diagnostic.switchToLocationSettings();
但是,我看到其他应用程序在启动时会询问问题以及用户何时选择“是”'该应用只需自动启用用户GPS,而无需将其带到设置页面。
我如何复制这个"自动启用"行为?
答案 0 :(得分:0)
您可以使用cordova.plugins.diagnostic
- cordova-plugin-request-location-accuracy
的配套插件(在Android上)执行此操作:
添加:
cordova plugin add cordova-plugin-request-location-accuracy
然后使用它:
function onRequestSuccess(success){
console.log("Successfully requested accuracy: "+success.message);
}
function onRequestFailure(error){
console.error("Accuracy request failed: error code="+error.code+"; error message="+error.message);
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}
cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);