我使用cordova-plugin-request-location-accuracy插件提示用户打开位置(如果尚未打开)。但是提示没有显示,我收到以下错误
准确性请求失败:错误代码= 4;错误消息=用户选择不进行所需的位置设置更改。
以下是我称之为插件
的代码部分function init() {
document.addEventListener("deviceready", watchPosition, false);
}
function watchPosition() {
cordova.plugins.backgroundMode.enable(); // enable backgroundMode
// Check if location settings are turned on. Prompt user if not turned on
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);
// start geolocation
checkPeriodically = setInterval(checkTime, 10000);
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
...
程序的其余部分运行正常(手动打开位置时)。是什么原因导致失败?谢谢。