Abhishek
Abhishek

Reputation: 69

Cordova geolocation plugin issue

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

Upvotes: 2

Views: 1634

Answers (1)

Neil Cresswell
Neil Cresswell

Reputation: 1165

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/

Upvotes: 1

Related Questions