$cordovaGeolocation issue when GPS is off


#1

Hello i have already working the plugin, but when i run the app and the GPS is off then throw me the exception, that’s ok, but when i turn on the GPS keep throwing the error, i have to close the app and then run it again with the GPS turned on and then it works perfect, even when i turn it off throw error but when turn on again it works perfect.

the issue is when i run the app when is off.

index.html :

<script src="js/ng-cordova.min.js"></script>

controllers.js:

.controller('InfoController', function($scope, $cordovaGeolocation){
        
        var posOptions = {timeout: 20000, enableHighAccuracy: true}

        $scope.where = function(){
           $cordovaGeolocation.getCurrentPosition(posOptions)
            .then(function(position){
                var lat  = position.coords.latitude
                var long = position.coords.longitude
                alert('lat'+lat);
                alert('long'+long);  
                location.href = location.origin;
            }, function(error){
                alert('error: '+error);
                

            });
        };
  
})

it runs on a Samsung Galaxy Note 3 with Android 5.0

Thank’s for any help you can give me.


#2

Use plugin sk.tamex.locationandsettings

my code: https://gist.github.com/brunoksato/5e7f9b2916289d1649a4

you can only call when you are sure that GPS is enabled, if not you will have an app that could not get over the location to restart the app