getCurrentPosition Error-callback doesnt fire


#1

Hi guys

Im using ng-cordova geolocation and using getCurrentPosition.
When my GPS on phone is working, im getting the correct position. but when its turned-off , neither the success callback nor the error callback is firing,so I have no way of knowing when user’s gps is off.
Im attaching my code

function hb() {
  console.log('hb running');
  if(processing) return;
  processing = true;
  navigator.geolocation.getCurrentPosition(function(position) {
    processing = false;
    console.log("target location" + lat, long);
    console.log("my position " + position.coords.latitude, position.coords.longitude);
    var dist = getDistanceFromLatLonInKm(lat, long, position.coords.latitude, position.coords.longitude);
    console.log("dist in km is "+dist);
    if(dist <= minDistance) callback();
  },onError,{enableHighAccuracy: true});
}

function onError(error) {
  processing = false;
  alert('code: '    + error.code    + '\n' +
    'message: ' + error.message + '\n');
}

#2

What do you mean by turned-off? You mean in a background? Or just turned off display?


#3

I meant the GPS is turned-off (I closed it from the top bar on my android phone before starting the app).
sorry for not being clear.
Thanks.


#4

To check if GPS is on use:

https://www.npmjs.com/package/cordova.plugins.diagnostic

Method isLocationEnabled: https://www.npmjs.com/package/cordova.plugins.diagnostic#islocationenabled


#5

Thanks I’ll definitely use it!
But thats still doesnt explain why the error-callback doesnt fire when the gps is turned off and im using getCurrentLocation.
Its like getCurrentLocation returns nothing - not an error and no success.

Any ideas/suggestions?
Thanks


#6

Try using:

enableHighAccuracy: false

when GPS is off


#7

Doesnt change anything. Still getting notthing.
Could it be that getCurrentPosition justs get stuck? or enters some loop and therfore doesnt return anything?

And is callback the correct way of working with getCurrentPosition or maybe I should use promises?

Thanks again