2

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});
Abhishek
  • 69
  • 5

1 Answers1

1

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/

Neil Cresswell
  • 1,145
  • 8
  • 20
  • Thanks @Neil Cresswell we will try it. – Abhishek Dec 29 '16 at 07:30
  • Sorry I'll find it very interesting and dont take me wrong here that I have to correct you, @Neil Cresswell, but this is not quite true. This plugin is based on the [html5 geolocation api](https://dev.w3.org/geo/api/spec-source.html) that tells that "enableHighAccuracy attribute provides a hint that the application would like to receive the best possible results", so you tell the api that you want to use gps/glonass/galileo/beidou but there is no guarantee that the coords are coming from these satellite-geotechs so this api is also allowed to fallback on less accurate techs like wifi/gsm. – Blauharley Dec 29 '16 at 17:23
  • As the referenced sentence tells: a app wants to use high accurate techs if its possible in a concrete situation then it will use high accurate techs otherwise it will use less accurate techs automatically if these can be used right now. It can also be read [here](http://stackoverflow.com/questions/15310742/if-i-have-access-fine-location-already-can-i-omit-access-coarse-location) when enableHighAccuracy is set to true both high and less accurate techs are allowed with andriod which of both can be used depends on the current location for instance. – Blauharley Dec 29 '16 at 17:24
  • To come to a conclusion when ACCESS_FINE_LOCATION is set then a app is allowed to use high and less accurate techs. removing ACCESS_FINE_LOCATION or setting enableHighAccurcacy to false do not have any effect on any less accurate techs. – Blauharley Dec 29 '16 at 17:31
  • The best you can do is to set enableHighAccuracy to true and set timeout and maximumAge as high as possible. This makes sure that you take full advantage of all geo-techs(high accurate and less accurate)and use cached coords as well. You can not do more because there are no more params. – Blauharley Jan 05 '17 at 22:19