Cordova geolocation plugin issue

1.6k views Asked by At

Cordova geolocation plugin works only with phone's GPS location. If phone GPS is not locked (e.g. being inside the building), then it should take the COARSE_LOCATION i.e. WIFI or Cellular tower.

I checked it by providing it only the permission of only ACCESS_COARSE_LOCATION and commenting out the code for ACCESS_FINE_LOCATION. We get error code: 3 (timeout) in this case.

    $scope.showpopup=function(status){
                 console.log("show pop up function called");
                 var cont;
                 switch (status) {
                    case 1:
                        cont = "User denied the request for Geolocation."
                        break;
                    case 2:
                        cont = "Location information is unavailable."

                        break;
                    case 3:
                        cont = "The request to get user location timed out."
                        break;
                    default:
                        cont = "An unknown error occurred."
                        break;
                }
                $ionicPopup.alert({
                    title: 'Gps error',
                    content: cont
                });
        };


 navigator.geolocation.getCurrentPosition(
    function(position){
        //Variables to use for showing latitude and longitude by position.coords .
    },function(error){
        $scope.showpopup(error.code);
        },{timeout:10000,maximumAge:60000,enableHighAccuracy:true});
1

There are 1 answers

5
Neil Cresswell On

You have enableHighAccuracy set to true, which indicates you want GPS. Change it to false and you'll then be able to get a network-based (wifi or cellular) position instead.

For additional details, please see:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/