Search code examples
androidioscordovageolocationcordova-plugins

Cordova Plugin Geolocation Timeout on IOS 11


I visited all links about this problem and none helped me.

I get the error code 3 (timeout) in response always when execute the method "getCurrentLocation" from "cordova-plugin-geolocation" on IOS .

follow my code:

getCurrentPosition() {
 return new Promise(function (resolve, reject) {
  document.addEventListener("deviceready", function(){
    navigator.geolocation.getCurrentPosition((position) => {
      resolve(position);
    }, (error) => {
      reject(error);
    }, {
      timeout: 10000
    });
  }, false);
 });
}

I upgraded all plugins and engines and the error persisted. Follow my current versions:

  • cordova 8.0.0;
  • cordova-ios 4.5.4;
  • cordova-android 7.0.0;
  • cordova-plugin-geolocation 4.0.0.

Solution

  • After the hardwork, I found the fix. I added the follow keys in "/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>