getCurrentPosition not working after turning the GPS off on the device even if it turned on again?


#1

navigator.geolocation.getCurrentPosition not working after turning the GPS off on the device even if it turned on again ? and also it keep getting error if i start the apps with the GPS is off and keep error even if the GPS turned on again while the App is runing, only if i start the App and the GPS is on … it work only in this situation. any solution ?

                    var myoption = {
                        maximumAge: 0,
                        timeout: 10000,
                        enableHighAccuracy: true
                    };
                    $scope.setGpsVisible(true);
                    navigator.geolocation.getCurrentPosition(function (position) {

                        var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                        $scope.positions.push({
                            lat: pos.k,
                            lng: pos.D
                        });
                        console.log(pos);
                        $scope.map.setCenter(pos);
                        $scope.map.markers[0].setPosition(pos);
                        $scope.myCurrentPosLat = pos.k;
                        $scope.myCurrentPosLng = pos.D;
                        $ionicLoading.hide();
                    }, function (err) {
                          $ionicLoading.hide();
                      navigator.notification.alert(
    'error !!',  // message
    function(){},    
    'error msg',       
    'done'               
);
                    
                    }, myoption);

3g/4g network
#2

That’s because that method is only fired once. You either need something to detect when the GPS is turned ON/OFF and then call getCurrentPoisition , or use the watchPosition method.

http://ngcordova.com/docs/plugins/geolocation/


#3

@joseadrian i fire the getCurrentPosition from a button on my view, so its not only once, if i click this button and my GPS was on before starting the App it success , if i turend the GPS off and click this button i will get error and i will keep getting error even if i turn the GPS on again …


#4

That’s weird. What’s the error message you get?


#5

@joseadrian am keep getting Timeout Expired , my timeout option is 10000 … so ?


#6

Have you tried setting the timeout to more than 10 seconds?


#7

What device you are testing with?


#8

@pcr am using galaxy note 4


#9

@joseadrian yes i did , the same


#10

Did you wrap the function in:

document.addEventListener(“deviceready”, function () {
$cordovaPlugin.someFunction().then(success, error);
}, false);

// OR with IONIC

$ionicPlatform.ready(function() {
$cordovaPlugin.someFunction().then(success, error);
});


#11

The code above is for $cordova functions. you should also wait for device ready for you code.
Did you try $cordova??


#12

@pcr also the same , i checked with another device, galaxy note 1 also the same


#13

I have the same problem on Android devices, iOS everything right, any solution that you have found?


#14

I have the exact same problem, when opening the app with the GPS on everything works, but if i turn off the GPS and on again I get Timeout error. same goes for opening the app if the gps is off, turning it on while inside the app dosent help.

is there a way to Initialize the plugin?

Im using one plus one ad my developing device,

any one solved this issue?


#15

i joined to question too i have this issue on wp8 on android i didnt remeber i will check later


#17

I still have a problem. Does someone has found a workaround (except testing with another plugin if it’s on or off) ?

Thanks


#18

I have the same problem. Anyone with news about the issue?


#19

Same error here. Have you found a solution?


#20

same issue here. anyone found a solution for this?


#21

Same issue, has anyone found solution?