This is a migrated thread and some comments may be shown as answers.

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

3 Answers 290 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Osahon
Top achievements
Rank 1
Osahon asked on 27 Dec 2017, 09:09 PM

I utilized the NativeScript Geolocator plugin with an Accuracy.high option (see code extract below) 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:

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

 

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.


3 Answers, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 28 Dec 2017, 07:50 AM
Hello Osahon,

Trying to reproduce the issue while using this test project but on my side, the Android device is returning the exact same coordinates from both nativescript-geolocation and Google Maps application. What might be happening is that perhaps you are receiving old location as discussed here. Try to fetch the current location while setting maximumAge property and then print the timestamp to verify that the location is from a recent timestamp.

For example:
var location = geolocation.getCurrentLocation({desiredAccuracy: Accuracy.high, maximumAge: 5000, updateTime: 5000, timeout: 20000})
     .then(function(loc) {
          if (loc) {
              console.log(loc.timestamps);
              // more code follows here
         }

Please, note that nativescript-geolocation is not part of NativeScript UI suite (nativescript-pro-ui) and any issue related to this plugin can be answered in the plugin's repository. You can also find help in the NativeScript community channels like https://discourse.nativescript.org/

Regards,
Nikolay Iliev
Progress Telerik
Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
0
Osahon
Top achievements
Rank 1
answered on 01 Jan 2018, 05:29 PM

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

 

0
Nick Iliev
Telerik team
answered on 02 Jan 2018, 07:32 AM
Hello Osahon,

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't 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.

As the issue is not related to NativeScritp UI, I would suggest continuing logging the info in the related issue.

Regards,
Nikolay Iliev
Progress Telerik
Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
Tags
General Discussion
Asked by
Osahon
Top achievements
Rank 1
Answers by
Nick Iliev
Telerik team
Osahon
Top achievements
Rank 1
Share this question
or