7

navigator.geolocation.getCurrentPosition in cordova/android gives max 10 meter accuracy. I didn't use any plugin for geolocation. But some other apps shows 3 meter accuracy for the same place.

navigator.geolocation.getCurrentPosition won't give better accuracy?

Mohammed H
  • 6,326
  • 12
  • 72
  • 119
  • in which platform? are you using `enableHighAccuracy: true`? – jcesarmobile Feb 26 '18 at 10:13
  • @jcesarmobile Yes, i am using. – Mohammed H Feb 26 '18 at 10:23
  • And in which platform? – jcesarmobile Feb 26 '18 at 10:49
  • @jcesarmobile android. – Mohammed H Feb 26 '18 at 11:05
  • @HabeebPerwad I linked your question to mine, having the same issue https://stackoverflow.com/questions/49348489/cordova-geolocation-accuracy-gets-capped-at-10-m – Mirko Mar 18 '18 at 13:39
  • @Mirko Here is my understanding. Earlier there were no support for geolocation from the browser component in android. So the plugin had a native android location code to get the location. Once the browser component started providing gelocation, they dropped [the Android Geolocation Code](https://github.com/apache/cordova-plugin-geolocation/blob/0.3.7/RELEASENOTES.md). Look like the browser geolocation code is giving maximum 10m accuracy irrespective of GPS availability or the device have better last know location data. – Mohammed H Mar 19 '18 at 05:37
  • @Mirko I took old tag 0.3.6 and [modified for my purpose](https://github.com/habeebperwad/cordova_geolocation_old/). – Mohammed H Mar 19 '18 at 05:39
  • @HabeebPerwad we have always used the geolocation plugin 2.2.0 and we used to have no issues at all (4/6 meters accuracy), now it is suddenly capped at 10m – Mirko Mar 19 '18 at 12:41
  • @Mirko No idea what happened to it. I couldn't find any reference mentioning that it will be capped to 10m in geolocation. – Mohammed H Mar 20 '18 at 05:08
  • Are there any major issues with pre 0.3.6 versions? – Marty.H May 27 '18 at 00:38
  • @Marty.H No idea bro. – Mohammed H May 27 '18 at 03:59
  • I answered a similar question here https://stackoverflow.com/questions/49348489/cordova-geolocation-accuracy-gets-capped-at-10-meters/52663008#52663008 – Mirko Oct 05 '18 at 12:45

1 Answers1

4

Sadly the cordova-plugin-geolocation for Android doesn't provide any native code, just have the minimal code to handle the permissions for Android 6+. For getting the location it uses the WebView implementation of geolocation, so if using enableHighAccuracy: true you don't get the accuracy you expect, there is nothing you can do about it (maybe complain to Google so they improve it in future System WebView updates) The results will probably vary from vendors/Android versions.

So if you need better accuracy you should search for a different plugin that uses native code for getting the location instead of using the one that the WebView provides. There are a few of them, better search for "background geolocation", as the ones providing background geolocation use native code.

jcesarmobile
  • 45,750
  • 8
  • 107
  • 152
  • There is any reference stating that webview will give only max 10 meter accuracy? – Mohammed H Feb 26 '18 at 11:50
  • They had native code till [tag 0.3.6](https://github.com/apache/cordova-plugin-geolocation/tree/0.3.6) – Mohammed H Feb 26 '18 at 11:54
  • 1
    No, there is no information about the internals of the WebView geolocation implementation or accuracy, as I say, it might vary on different devices or vendors. The 0.3.6 version of the plugin is very old, the native code is really out of date, it won't be able to handle the Android 6+ permissions, so better look for an alternative. – jcesarmobile Feb 26 '18 at 12:21
  • I used to get up to 4 meters, now I get 10 meters max as well, after upgrading to Oreo. – Mirko Mar 10 '18 at 17:56
  • We used to get down to 4 meters on our app, now we had lots of users complaining about the accuracy not going below 10 meters. We are baffled, as we did not change anything on our app. – Mirko Mar 17 '18 at 19:20
  • 1
    @jcesarmobile Also, someone is facing the same problem with native code, see https://stackoverflow.com/questions/49044731/fusedlocationapi-performance-issue-accuracy-seems-capped-at-10-0-meters – Mirko Mar 18 '18 at 11:51
  • @jcesarmobile I added my own question here https://stackoverflow.com/questions/49348489/cordova-geolocation-accuracy-gets-capped-at-10-m – Mirko Mar 18 '18 at 13:39
  • For those interested, I reported this to the Chrome team which opened an issue to trace this: https://bugs.chromium.org/p/chromium/issues/detail?id=857113&can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort= – Juri Jun 28 '18 at 06:18