Different Location Accuracy Result on Google Map and NativeScript Geolocator On Same Mobile Device


#1

I utilized the NativeScript Geolocator plugin (with an Accuracy.high option) to obtain the longitude & latitude of my location on an Android device (version 7.0). The horizontal/vertical accuracy of the location returned was a range of 500 - 1,500 metres.

When I put the location obtained on Google Map (using the required Latitude,Longitude pair), the location is very far from my actual location (corresponding to the horizontal/vertical accuracy).

However, when I use the Google Map mobile app on the same device to obtain my current location it is very accurate (as displayed by the blue marker/indicator).

I would have thought that the accuracy of the location provided by the NativeScript Geolocator plugin (using the Accuracy.high option) should be about the same as that of Google Map mobile app on the same device since they use the same Google Play Services.

Could someone help with this.


#2

I think some code snippet will help us to see what is the issue here.


#6

@manojdcoder The extract from the code is below:

// Import Section
import { Component, ElementRef, OnInit, ViewChild } from "@angular/core";
import { View } from "ui/core/view";
import * as geolocation from "nativescript-geolocation";
import * as camera from "nativescript-camera";
import { Image } from "ui/image";
import { Accuracy } from "ui/enums";

// Function to get the current location
buttonGetLocationTap() { 
    geolocation.isEnabled().then(function (isEnabled) {
        if (!isEnabled) {
            geolocation.enableLocationRequest().then(function () {}, function (e) {
                console.log("Error: " + (e.message || e));
            });
        }
    }, function (e) {
        console.log("Error: " + (e.message || e));
    });

    if(geolocation.isEnabled()) {
      var location = geolocation.getCurrentLocation({desiredAccuracy: Accuracy.high, updateTime: 5000, timeout: 20000}).
      then(function(loc) {
          if (loc) {
              console.log("Current location is: Longitude => " + loc.longitude + "; Latitude => " + loc.latitude +
                          "; Hor.Accuracy: "+loc.horizontalAccuracy+"; Ver.Accuracy: "+loc.verticalAccuracy);
          }
      }, function(e){
          console.log("Error: " + e.message);
      });
    }    
  }

#7

You had mentioned it is not showing right location in Google Maps, you must be able to just add the marker with given loc.latitude & loc.longitude, not sure why you need accuracy to add marker.


#9

@manojdcoder The essence of the work is to get a fairly precise location of the user, hence, the location needs to be accurate enough. The location obained would also be sent to a server which would be used for other spatial analysis.

My main point is this: I would have thought that the accuracy of the location provided by the NativeScript Geolocator plugin (using the Accuracy.high option) should be about the same as that of Google Map mobile app on the same device since they use the same Google Play Services.


#10

A similar issue was reported in the link below:
https://github.com/NativeScript/nativescript-geolocation/issues/69


#11

@manojdcoder I think I finally have a clue as to what might be the likely cause of the difference in accuracy. I observed the following on my device (Tecno Carmon CX):

  • Under Settings -> Location -> Mode, there are 3 options:
    • High Accuracy (Use GPS, Wi-Fi, Bluetooth, or cellular networks to determine location)
    • Battery Saving (Use Wi-Fi, Bluetooth, or cellular networks to determine location)
    • Device only (Use GPS to determine location)

When the app sends an enable location request, I get a prompt - “To continue, let your device turn on location, which uses Google’s location service…” This selects the first option (High Accuracy) among the 3 options stated above. However, it seems that with this option on my device, the Geolocation plugin isn’t using the device GPS to determine the location as expected (the documentation states that it would use the most accurate location provider that is available).

When I attempt to change the Settings -> Location -> Mode option to either “Battery Saving” or “Device only”, the app keeps giving the initial prompt to turn on location which sets the option back to “High Accuracy”. The issue seems to be that with this option, the Geolocation plugin doesn’t use the device GPS to determine the location. How? I discovered this to be so by manually changing the Settings -> Location -> Mode option to “Battery Saving” which would use Wi-Fi, Bluetooth, or cellular networks to determine location. With this option, on the Google Map android app the current location marker (blue indicator) is exactly the same as the inaccurate position returned by the Geolocation plugin. However, when I change the option to “Device only” which would use GPS to determine location, the Google Map android app returns an accurate location.

Is there a way to ensure that the Geolocation plugin only uses the device GPS to determine the location and returns say a NULL location otherwise OR is there a way to make the Geolocation plugin accept other location options on my device - e.g “Device only”?


#12

@osahonoduware You can do something like this to know the provider

geolocation.getCurrentLocation({ 
 desiredAccuracy: Accuracy.high, 
 maximumAge: 5000, 
 timeout: 20000 
}).then((location) => {
  // location.android will be `android.location.Location` 
  location.android.getProvider() 
});

#13

@manojdcoder Thanks for your response. I will try this and give you feedback.


#14

I got an error for the statement:
location.android.getProvider()

It appears such method/property doesn’t exist for the location.


#15

getProvider() works for me.


#16

Here is another way to get best last known location from all available providers. Hope this might work for you.