2016-05-06 2 views
1

にエラーコード3をタイムアウトになりました。 コルドバプラグインジオロケーションは、バージョン2.2.0です。コルドバイオンジオロケーションは失敗:位置の取得は、私がコルドバとイオンを使用して、アプリ、IOS /アンドロイドに取り組んでいるのiOS

それはアンドロイドに良い取り組んでいます。 が、iOSでは、ウォッチャ4回から新しい位置を受け取った後、私は次のエラーを持っている:
PositionError {code: 3, message: "Position retrieval timed out.", PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}

誰かが解決策を持っていますか?ここ

私のコードの一部:

var posOptions = { 
    timeout   : 10000, 
    enableHighAccuracy: false 
}; 

var watchOptions = { 
    timeout : 10000, 
    enableHighAccuracy: false // may cause errors if true 
}; 

/** 
* Sets initial user position. 
*/ 
$ionicPlatform.ready(function() { 
    console.log('ready'); 
    $cordovaGeolocation 
     .getCurrentPosition(posOptions) 
     .then(function (position) { 
      setLocationData(position); 
     }, function (err) { 
      // error 
     }); 

    /** 
    * Watches for user position. 
    */ 
    $timeout(function() { 
     console.log(watchOptions); 
     var watch = $cordovaGeolocation.watchPosition(watchOptions); 
     watch.then(
     null, 
     function (err) { 
      // error 
      console.log(watchOptions); 
      console.log(err); 
      alert(err); 
     }, 
     function (position) { 
      console.log(watchOptions); 
      console.log('refresh') 
      alert('refresh'); 
      setLocationData(position); 
     }); 
    }, 10000); 

}); 

答えて

0

私はもっとあなたを助けることができないということは本当に残念ですが、これは私が過去に使用したコードです...

(それ

var getLocation = function() { 
    var deferred = Q.defer(); 
     var options = { 
     enableHighAccuracy: true, 
     timeout: 5000, 
     maximumAge: 0 
     }; 
     var onSuccess = function(position) {  
     var lat = position.coords.latitude; 
     var lng = position.coords.longitude; 
     deferred.resolve({lat : lat, lng : lng}); 
     }; 

     var onError = function() { 
     var lat = -77.847635; 
     var lng = 166.760616; 
     deferred.resolve({lat : lat, lng : lng}); 
     }; 

     if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(onSuccess, onError, options); 
     } else { 
     onError(); 
     } 
    return deferred.promise; 
    }; 

は、おそらく間違って行くことができますたくさんのものがあります)PhoneGapのビルドを使用して、コルドバアプリケーションでした。すべての最初のアプリは、場所を使用する許可をユーザーに尋ねるのですか?それは私のために働いていなかったいくつかの例では

- とエラーコードは一貫していませんでした - ので、私はこれを行うことによって、私の問題を解決し、南極へのフォールバック...

+0

をはいアプリがアクセス権を求めますそれは非常に行く動作するため それは奇妙だ、アプリケーションが4時間に私の右の位置を与える、と私はエラーを取得した後、「位置検索がタイムアウトしました」アンドロイドにod – Jeffrey

0

があります: Watcherは持っているときエラー。それを停止して再起動します。

ここに私のコード:

/** 
    * Sets initial user position. 
    */ 
    $ionicPlatform.ready(function() { 
     console.log('ready'); 
     $cordovaGeolocation 
      .getCurrentPosition(posOptions) 
      .then(function (position) { 
       setLocationData(position); 
      }, function (err) { 
       // error 
      }); 

     /** 
     * Watches for user position. 
     */ 
     $timeout(function() { 
      console.log(watchOptions); 
      watchLocation(); 
     }, 10000); 

    }); 

    function watchLocation(){ 
     var watch = $cordovaGeolocation.watchPosition(watchOptions); 
     watch.then(
      null, 
      function (err) { 

      watch.clearWatch(); 
      watchLocation(); 
      }, 
      function (position) { 

      setLocationData(position); 
      }); 
    } 
0

私は次のようにiOSのコルドバプラグイン(CDVLocation.m)を変更することで解決してきた:

if (enableHighAccuracy) { 
    __highAccuracyEnabled = YES; 
    // Set distance filter to 5 for a high accuracy. Setting it to "kCLDistanceFilterNone" could provide a 
    // higher accuracy, but it's also just spamming the callback with useless reports which drain the battery. 
    //self.locationManager.distanceFilter = 5; //OLD CODE 
    self.locationManager.distanceFilter = kCLDistanceFilterNone; //NEW CODE 
    // Set desired accuracy to Best. 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
} else { 
    __highAccuracyEnabled = NO; 
    //self.locationManager.distanceFilter = 10; //OLD CODE 
    self.locationManager.distanceFilter = kCLDistanceFilterNone; //NEW CODE 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers; 
} 

出典:Apache Cordova geolocation.watchPosition() times out on iOS when standing still

関連する問題