科尔多瓦的地理位置精确度被限制在10米 [英] Cordova geolocation accuracy gets capped at 10 meters

查看:152
本文介绍了科尔多瓦的地理位置精确度被限制在10米的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 cordova gelocation插件和方法 navigator .geolocation.watchPosition()与选项 enableHighAccuracy:true 来跟踪用户位置并获得最准确的结果。



我们的应用程序已经使用了1年多,而且我们以前没有任何设备可以获得非常好的定位精度,外部4/6米,天空晴朗时没有任何问题。

最近,我们的许多用户报告无论他们做什么都无法获得小于10m的精度。



我们决定自己测试一下,发现有同样的问题。最初,我们认为我们在最新版本中引入了一些错误,我们对所有内容进行了三重检查,但没有更改涉及地理位置的代码/依赖项。

我们测试了旧版本的我们应用程序也是如此,我们确信它有可能获得4米精度,但令人惊讶的是,它们也无法正常工作,准确度达到了10米。

我们尝试了不同的版本的Android,我们可以在任何平台上从5(棒棒糖)到8(奥利奥)重现此问题。我们在iOS 10/11上也遇到同样的问题。再次,我们没有在几个月内更新应用程序。



最近有一个关于同一问题的问题 here

其他人拥有相同的使用Android本地代码的问题此处

有谁知道发生了什么事?这是一个许可问题吗?定位服务也设置为高精度。

为了完整起见,我们可以使用旧版本(2.x)获得3/4米的精确度,这个插件



这是唯一的出路吗?



我们宁可不引入额外的依赖项,以实现开箱即用的功能。



非常感谢

解决方案

查看源代码:
$ b $旧插件2.x)来源

  watchPosition:function(success,error,args){
var win = function(){
var geo = cordova.require('cordova / modulemapper')。getOriginalSymbol(window,'navigator.geolocation');
geo.watchPosition(成功,错误,{
enableHighAccuracy:args [1]
});
};
exec(win,error,Geolocation,getPermission,[]);
},

新插件(master)来源

  watchPosition:function(success,error,args){
var pluginWatchId = utils.createUUID();

var win = function(){
var geo = cordova.require('cordova / modulemapper')。getOriginalSymbol(window,'navigator.geolocation');
pluginToNativeWatchMap [pluginWatchId] = geo.watchPosition(success,error,args);
};
$ b $ var fail = function(){
if(error){
error(new PositionError(PositionError.PERMISSION_DENIED,'Illegal Access'));
}
};
exec(win,fail,Geolocation,getPermission,[]);

return pluginWatchId;
},

在老插件代码 enableHighAccuracy 中是一个布尔值由(arg1 of array)设置。



使用新版本的插件,您需要将arg作为JSON传递给该标志集: {enableHighAccuracy:true} strong>以高精确度重现对 geo.watchPosition 函数的相同调用。



旧方式:

  navigator.geolocation.watchPosition(geolocationSuccess,
geolocationError,
[false,true]);

新方式

  navigator.geolocation.watchPosition(geolocationSuccess,
geolocationError,
{enableHighAccuracy:true});


We use the cordova gelocation plugin and the method navigator.geolocation.watchPosition() with the option enableHighAccuracy: true to track the user location and get the most accurate results.

Our app has been around for more than 1 year and we used to have no problems with any device getting a very good location accuracy, 4/6 meters when outside and the sky is clear.

Lately, many of our users are reporting not being able to get anything less than 10m accuracy no matter what they do.

We decided to test it ourselves and we found to have the same issue. Initially, we thought we introduced some bug in our latest release, we triple checked everything but we made no changes to code/dependencies involving geolocation.

We tested older versions of our app as well, where we are sure it was possible to get like 4m accuracy, but surprisingly they do not work either, accuracy is capped at 10m.

We tried different version of Android and we can reproduce the issue on any platform from 5 (Lollipop) to 8 (Oreo). We also have the same problem on iOS 10/11. Again, we have not updated the app in months.

There is a recent question about the same issue here:

Someone else is having the same problem using Android native code here

Does anyone know what is going on? Is it a permission issue? Location Services are set to High Accuracy as well.

For the sake of completeness, we are able to get 3/4 meters accuracy using the old version (2.x) of this plugin

Is it the only way to go?

We would rather not introduce an extra dependency for something that was working so well out of the box.

Many thanks

解决方案

Looking at source code:

Old plugin (2.x) Source:

  watchPosition: function(success, error, args) {
    var win = function() {
        var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
        geo.watchPosition(success, error, {
            enableHighAccuracy: args[1]
        });
    };
    exec(win, error, "Geolocation", "getPermission", []);
},

New Plugin (master) Source:

watchPosition: function(success, error, args) {
    var pluginWatchId = utils.createUUID();

    var win = function() {
        var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
        pluginToNativeWatchMap[pluginWatchId] = geo.watchPosition(success, error, args);
    };

    var fail = function() {
        if (error) {
            error(new PositionError(PositionError.PERMISSION_DENIED, 'Illegal Access'));
        }
    };
    exec(win, fail, "Geolocation", "getPermission", []);

    return pluginWatchId;
},

In OLD plugin code enableHighAccuracy is a boolean set by (arg1 of array).

With NEW version of plugin you need to pass arg as JSON with that flag set: {enableHighAccuracy: true} to reproduce same call to geo.watchPosition function with high accuracy.

Old Way:

navigator.geolocation.watchPosition(geolocationSuccess,
                                                  geolocationError,
                                                  [false,true]);

New Way:

navigator.geolocation.watchPosition(geolocationSuccess,
                                                  geolocationError,
                                                  { enableHighAccuracy: true });

这篇关于科尔多瓦的地理位置精确度被限制在10米的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆