Geolocation timeout vs location permission error


i am using $cordovaGeolocation.getCurrentPosition to get user’s location. I need to display different error message if location services are turned off for this app or getting location times out.

if I don’t set any options then I can get error if lcoation service is turned off, but if I set options as { enableHighAccuracy: true, timeout: 15*1000, maximumAge: 60000 } Then I always get timeout error regardless of my location permission settings.

I need to get error first if location services are turn off, and if they are ON, then get timeout error if request times out.

1 Like

I am handling location services error like this

     google.maps.event.addDomListener(window, 'load', function() {
        navigator.geolocation.getCurrentPosition(setCurrentPosition, showGPSError, {
            enableHighAccuracy: true,
            timeout: 10000

   function showGPSError (error) {
        var content;
        switch (error.code) {
            case error.PERMISSION_DENIED:
                content = "User denied the request for Geolocation."
            case error.POSITION_UNAVAILABLE:
                content = "Location information is unavailable."
            case error.TIMEOUT:
                content = "The request to get user location timed out."
            case error.UNKNOWN_ERROR:
                content = "An unknown error occurred."
            title: "GPS Error",
            cssClass: "background-color: #4BAF33",
            content: content


Unfortunately in my case I always get error.TIMEOUT even if I disable app permission to use my location.

Created ‘SO’ question also:

You need to go through this article - , May be helpful.

Have you added GPS plugins ?

Sorry but this is not helpful. Basically I need to know when user turns off location permission for current app.

You better use plugin … It will directly check whether gps is enabled or not.

I did use this. On Android 6.0 it can only tell if global location settings are turned off. But it doesn’t know if App’s specific location permission is turned off

Did u tried isGpsLocationEnabled() method of that

Yes ditto, Got error saying isGpsLocationEnabled is not a function Have you tried it yourself?

Uninstall and reinstall the plugin… Use it like this

                if(enabled ){
                } else {

It worked for me… You can read the document from the above link…

I get the following error with the cordova plugin: