Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

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

Open
oduwareosahon opened this issue Dec 25, 2017 · 10 comments

Comments

@oduwareosahon
Copy link

Similar to the issue raised in the following link which has been closed:
#69

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 to obtain my current location it is very accurate (as displayed by the blue marker/indicator).

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

Could someone help with this.

@NickIliev
Copy link

@oduwareosahon I've tried to reproduce the issue using this test application but to no avail.
Please provide more additional information (sample application, project dependencies, API levels of used devices/emulators) so we could investigate further based on your specific scenario.

@oduwareosahon
Copy link
Author

You can replicate this issue by testing the following on a physical android device:
(1a) Following the example in the code extract below, create a simple NativeScript project that uses the NativeScript Geolocator plugin to obtain your current location (using the Accuracy.high option). To keep this simple, print out the location (longitude/latitude as well as the horizontal/vertical accuracy) to the console.
(1b) Display the location (longitude & latitude values) obtained from the above step on a map.

(2) Open Google Map Android App on the same physical device (install it if not installed). The blue marker should indicate your current location.

(3) Compare the location displayed on a map in Step 1 with that of Step 2. You should notice that the location on the Google Map App (Step 2) is very accurate, while the location obtained from NativeScript Geolocator plugin (Step 1) is very inaccurate (ranges between 500 - 1,500 metres from the actual location).

My question is why the difference in accuracy on the same physical device when (according to the documentation) they both use the same Google Play Services.

CODE EXTRACT
// 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);
  });
}    

}

@oduwareosahon
Copy link
Author

@NickIliev 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"?

@NickIliev
Copy link

NickIliev commented Jan 2, 2018

Thank you for providing the additional information.
I have re-tested the scenario once again using a real device and changing the modes to "Device only" and "Battery Save" but once again was not able to
reproduce the issue. Each time the mode was changed, and the method getCurrentLocation s triggered, the nativescript-geolocator prompts a dialog asking for permissions
to change the location mode to High Accuracy.The above was tested on LG and Samsung devices and some emulators and worked as expected on all tested devices.
I can not test on your specific device (Tecno Carnon CX), but as far as I understand the test device is using Android 7 (API23), I was able to test successfully on an Android device with the very same versions of the operating system.What I can suggest is to test if the OS is successfully changing the location mode after giving permissions in the prompted dialog window

Let me know if accepting the mode change is successfully changing the Location mode settings on your device.(after tapping OK it should change the mode to Accuracy High)

The dialog prompt to letting the plugin change the mode to High Accuracy
screen shot 2018-01-02 at 9 26 14 am

@oduwareosahon
Copy link
Author

@NickIliev Thanks for your response. Yes, accepting the mode change is successfully changing the Location mode settings to Accuracy High on my device.

The issue seems to be that with the "Accuracy High" option, the Geolocation plugin doesn't use the device GPS to determine the location as expected (the documentation states that it would use the most accurate location provider that is available).

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 (Battery Saving), 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.

@lini lini added the question label Jan 5, 2018
@lini
Copy link
Contributor

lini commented Jan 5, 2018

GPS works better when the device is outside and not in a building. High Accurary/Device only modes will take some time to provide an accurate location (especially from a cold start). Battery saving mode does not use GPS and will usually provide a location faster, although it might not be as accurate.

If the timeout you set for the location request is not long enough, you might not get a GPS lock and a correct location in time. Try increasing it and see if it has any effect.

In your case, perhaps Google Maps is caching the last known location in some way and using it while the device tries to get a fresh one?

@DimitarTachev
Copy link
Contributor

Closing this issue due to inactivity

@ghost ghost removed the question label Jan 29, 2018
@Vallhay
Copy link

Vallhay commented Mar 12, 2018

Im having this exact same problem, the Accuracy using the plugin is terrible compared to Google Maps, Maps get my exact location while the plugin get me a 16-90mts accuracy while stationary or walking and 2500mts accuracy while driving. As it seem the plugin is not using my gps for location (Im using desiredAccuracy: Accuracy.high and my location config on Android is on High accuracy too)
Im testing this on a Lenovo Vibe K5 A6020L37 running Android 5.1.1

@radeva radeva reopened this Mar 13, 2018
@vakrilov vakrilov added this to Backlog in Plugins Team Apr 15, 2019
@mudlabs
Copy link

mudlabs commented Apr 2, 2020

Can confirm the accuracy is also WAY off on iOS too.

  • 10+ kilometres off in my test.

Here's the Playground I used.

Test method:

  1. Get location from Playground.
  2. Copy the location lat/lon coordinates into Google Maps.
  3. Use Google Maps Measure Tool to measure the distance from my known location and the plugins' output location.

Test Device:

  • iPhone 6s Plus
  • iOS 12.3.1

I also see no difference between High, and Any accuracy

  • The lat/lon coordinates are the same for both.
  • And both are way off in accuracy.

@mudlabs
Copy link

mudlabs commented Apr 7, 2020

After rolling my own implementations I have found

  • iOS eventually gets very accurate. Not sure how the wizards at Google get precise accuracy immediately in there Maps app, but my implementation gets there after a few seconds.
  • Android never gets accurate. For me it's first returned fix is all I ever get; it's about 3km off. Turning Google Location Accuracy off, so my device is forced to use GPS results in no location data at all.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Plugins Team
  
Inbox
Development

No branches or pull requests

7 participants