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

**URL:** <https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821>\
**Category:** ionic-v1\
**Created:** [February 26, 2016, 4:55am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821 "2016-02-26T04:55:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [February 26, 2016, 4:55am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/1 "2016-02-26T04:55:48Z")

</div>

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 !!

---

<div class="post-metadata">

**Author:** ![matthewhw1989](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@matthewhw1989](https://forum.ionicframework.com/u/matthewhw1989)\
**Post date:** [February 26, 2016, 10:03am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/2 "2016-02-26T10:03:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [February 26, 2016, 10:59am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/3 "2016-02-26T10:59:43Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![matthewhw1989](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@matthewhw1989](https://forum.ionicframework.com/u/matthewhw1989)\
**Post date:** [February 26, 2016, 11:20am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/4 "2016-02-26T11:20:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [February 26, 2016, 11:24am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/5 "2016-02-26T11:24:07Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![matthewhw1989](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@matthewhw1989](https://forum.ionicframework.com/u/matthewhw1989)\
**Post date:** [February 26, 2016, 11:33am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/6 "2016-02-26T11:33:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [February 26, 2016, 11:42am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/7 "2016-02-26T11:42:45Z")

</div>

tried ! no luck !

It used to work with this config before !

`enableHighAccuracy: false, timeout: 30000, maximumAge: 0`

All of a sudden it stopped working !

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [February 26, 2016, 2:39pm UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/8 "2016-02-26T14:39:32Z")

</div>

**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 !

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [March 14, 2016, 4:54am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/9 "2016-03-14T04:54:11Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![syrope](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/syrope/32/100275_2.png) [@syrope](https://forum.ionicframework.com/u/syrope)\
**Post date:** [September 29, 2016, 7:46pm UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/10 "2016-09-29T19:46:10Z")

</div>

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](https://scontent-mad1-1.xx.fbcdn.net/v/t1.0-9/13700084_10209030231046316_8844560510473254080_n.jpg?oh=feba842834f96f29b33b6ad402fac9ae&oe=586D9D7F)

---

<div class="post-metadata">

**Author:** ![Destroy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/destroy/32/94194_2.png) [@Destroy](https://forum.ionicframework.com/u/Destroy)\
**Post date:** [September 29, 2016, 9:07pm UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/11 "2016-09-29T21:07:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![syrope](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/syrope/32/100275_2.png) [@syrope](https://forum.ionicframework.com/u/syrope)\
**Post date:** [September 29, 2016, 9:56pm UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/12 "2016-09-29T21:56:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Destroy](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/destroy/32/94194_2.png) [@Destroy](https://forum.ionicframework.com/u/Destroy)\
**Post date:** [September 30, 2016, 9:59am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/13 "2016-09-30T09:59:19Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![RomnEmpire](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/romnempire/32/124028_2.png) [@RomnEmpire](https://forum.ionicframework.com/u/RomnEmpire)\
**Post date:** [May 2, 2019, 5:40am UTC](https://forum.ionicframework.com/t/cordovageolocation-always-timing-out-is-this-cordova-or-ionic-issue/44821/14 "2019-05-02T05:40:03Z")

</div>

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