getCurrentPosition Error-callback doesnt fire


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');


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


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.


To check if GPS is on use:

Method isLocationEnabled:


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?


Try using:

enableHighAccuracy: false

when GPS is off


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