IOS 11上的Cordova插件地理位置超时

时间:2017-12-20 20:13:37

标签: android ios cordova geolocation cordova-plugins

我访问了有关此问题的所有链接,没有人帮助过我。

在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。

1 个答案:

答案 0 :(得分:1)

辛勤工作之后,我找到了修复。我在" / 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>