我访问了有关此问题的所有链接,没有帮助我。
我从iOS上的" cordova-plugin-geolocation"中执行" getCurrentLocation"时始终在响应中获取错误代码3(超时)。
遵循我的代码:
getCurrentPosition() {
return new Promise(function (resolve, reject) {
document.addEventListener("deviceready", function(){
navigator.geolocation.getCurrentPosition((position) => {
resolve(position);
}, (error) => {
reject(error);
}, {
timeout: 10000
});
}, false);
});
}
我升级了所有插件和引擎,并且错误持续了。遵循我当前的版本:
- Cordova 8.0.0;
- Cordova-ios 4.5.4;
- Cordova-Android 7.0.0;
- Cordova-Plugin-Geolocation 4.0.0。
努力后,我找到了修复程序。我在"/platform/ios/{project_name}/{project_name} -info.plist"中添加了关注键:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>My app requires constant access to your location, even when the screen is off.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>My app requires constant access to your location, even when the screen is off.</string>