$cordovaGeolocation Always Timing Out ! is this cordova or ionic issue?

No matter what the timeout is set or whether the high accuracy is true or false !!
$cordovageolocation always returning error code 3 error message Timeout expired

Heres my code :-

$ionicPlatform.ready(function() {

          var posOptions = {
             enableHighAccuracy: false,
             timeout: 30000,
             maximumAge: 0
         };
   $cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
       var lat  = position.coords.latitude;
       var long = position.coords.longitude;
       //alert(lat);
       var FormData = {
         'radius' : $localStorage.nearradius,
         'latitude' : lat,
         'longitude' : long
       };
       $http({
         method: 'POST',
         url: 'http://xyz.com/abc',
         data: FormData,
         headers: {'Content-Type': 'application/x-www-form-urlencoded','Authorization':undefined},
       })
       .success(function(data) {
           defer.resolve(data);
       })
       .error(function(data) {
   });
   }, function(err) {
       alert(err.code+" "+err.message);
   });

It always goes in function(err) …

Code is wrapped inside ionic platform ready !

Help is appreciated !!

1 Like

https://github.com/transistorsoft/cordova-background-geolocation-lt , this is a great plugin have used it before. might be an answer for your problems.

2 Likes

Thanks for your response ! its background geolocation plugin which will keep running i guess ! i just want to check/get user’s location once ! can i do that ?

have you got all permissions

"uses-permission android:name=“android.permission.ACCESS_COARSE_LOCATION” "
"uses-permission android:name=“android.permission.ACCESS_FINE_LOCATION” "
"uses-permission android:name=“android.permission.ACCESS_LOCATION_EXTRA_COMMANDS”

enableHighAccuracy: true might be better?

yess ! i have ! for debugging purpose i placed a alert for plugin’s response !
and plugin always times out with error code 3 that is timeout message according to documentation too…

tried with high accuracy too … no change :frowning:

maximum age should also be higher than 0 as this is not giving your gps chip long enough time to acquire a new gps hit. try 30 seconds as a test.

TIMEOUT (numeric value 3)
The length of time specified by the timeout property has elapsed before the implementation could successfully acquire a new Position object.

tried ! no luck !

It used to work with this config before !

enableHighAccuracy: false, timeout: 30000, maximumAge: 0

All of a sudden it stopped working !

Update:-

I tested it on kitkat device it worked without issues !!

Till now i was testing it on jellybean in which its still not working !

Any help is appreciated !

Anyhow i need this to work ! no config works on android now ! I even tried sample app in this tutorial
-> http://www.gajotres.net/using-cordova-geoloacation-api-with-google-maps-in-ionic-framework/

By @Gajotres !

even in this sample app it keeps timing out !

Cordova CLI: 6.0.0 Gulp version: CLI version 3.9.1 Gulp local: Ionic Version: 1.2.4 Ionic CLI Version: 1.7.13 Ionic App Lib Version: 0.6.5 OS: Node Version: v4.1.0

tried watch position instead of get current and still no luck

If the app starts with GPS on from the beginning. it works perfectly.
In case the App starts with GPS off , and later you turn GPS on, the plugin gets always timeout . error code = 3. no solution for this issue until now.
I share code example
https://scontent-mad1-1.xx.fbcdn.net/v/t1.0-9/13700084_10209030231046316_8844560510473254080_n.jpg?oh=feba842834f96f29b33b6ad402fac9ae&oe=586D9D7F

I had the same problem.
Solved it using timeout and recursion till success.

I am using this parameters:

var posOptions = {timeout: 1000, enableHighAccuracy: false, maximumAge: 0};

and i am trying the recursivity approach …

else if(err.code == 3) { console.log('Error: GPS Timeout! ERROR = ’ + err.code); $scope.centerOnMe(); }

but always timeout… Could you give an example? thank you for your response.

This is a very simple example, but I hope to help you:

function getLocation() {
  return $cordovaGeolocation.getCurrentPosiion();
}

function loadingLocation(deferred) {
  getLocation()
    .then(function(response) {
      deferred.resolve(response); // resolve the success value
    })
    .catch(function() {
      getLocation(deferred);  //when can not get location call again getLocation till success
    });

  return deferred;
}

var defer = $q.defer();
loadingLocation(defer); // this will return promise which will be resolved only with success

sir are you fixed above issue after add set above parameter actually its not working for me after add?