静止时,Apache Cordova geolocation.watchPosition()在iOS上超时 [英] Apache Cordova geolocation.watchPosition() times out on iOS when standing still

查看:356
本文介绍了静止时,Apache Cordova geolocation.watchPosition()在iOS上超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Apache Cordova的cordova-plugin-geolocation时,特别是使用watchPosition()时,我至少在iOS 8.1.3至8.3上遇到困难。正在发生的事情是,当用户移动时,坐标工作得很好,并且不断更新。但是,当用户停下片刻(比如设置的超时)时,会引发超时错误。第二个用户再次移动的坐标正在工作。



我们不能太多地增加超时时间,因为担心用户会合法地失去接收并且不得不重新记录他们的字段边界(农业应用)再次。这就是说我们把超时时间增加到了65000,并且仍然设法得到超时信息。



我现在的工作理论是,无论什么原因,如果没有检测到运动,插件是抛出超时消息而不是一次又一次地给我相同的坐标。我不知道这是否可能是某种省电功能或iOS和/或插件的实际错误。

  geoWatch = window.navigator.geolocation.watchPosition(
gpsChangeCoordinates,
function(error){
$(#signal)。html(Error:+ error.message);
$(#signal).css(background-color,red);
},
{maximumAge:3000,timeout:15000,enableHighAccuracy:true});
);

切换到getCurrentPosition()也是无效的,因为除非持续查询GPS,否则精度没有达到并保持在农业用途所需的水平。



这个问题没有出现在Android上。

解决方案是直接修改CDVLocation.m以删除distanceFilter。或者更具体地说:

  if(enableHighAccurary){
//剪下
// self.locationManager。 distanceFilter = 5; //原始,导致问题仍然存在
self.locationManager.distanceFilter = kCLDistanceFilterNone;
//截取
} else {

通过代码中的注释来判断这是一个意识到节省电池的决定,当用户移动5米或更多米时才发送更新。这对我的用例来说是有问题的。


When utilizing Apache Cordova's cordova-plugin-geolocation, specifically with watchPosition() I am encountering difficulties on at least iOS 8.1.3 through 8.3. What is happening is that when a user is moving, the coordinates work just fine and are continuously updating. However when the user stops for a few moments (say the timeout that is set), a timeout error is thrown. The second the user moves again the coordinates are working.

We cannot increase the timeout too much for fear that users will legitimately lose reception and have to re-record their field boundaries (agricultural application) over again. That said we increased the timeout to 65000 and still managed to get the timeout message.

My present working theory is that for whatever reason if no movement is detected then the plugin is throwing a timeout message rather than potentially give me the same coordinates over and over again. I am not sure if this might be some sort of battery saving functionality or an actual bug with iOS and/or the plugin.

geoWatch = window.navigator.geolocation.watchPosition(
    gpsChangeCoordinates,
    function(error){
        $("#signal").html("Error: "+error.message);
        $("#signal").css("background-color","red");
    },
    {maximumAge:3000, timeout:15000, enableHighAccuracy:true});
);

A switch to getCurrentPosition() is also not valid because unless the GPS is being continuously polled, the accuracy does not get to and remain at the levels needed for agricultural purposes.

This issue does not appear on Android.

解决方案

The solution is a modification to CDVLocation.m directly to remove the distanceFilter. Or more specifically:

if (enableHighAccurary) {
    // snipped
    // self.locationManager.distanceFilter = 5;// original, causes problems standing still
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    //snipped
} else {

Judging by the comments in the code this was a conscious decision in the name of battery saving to only send updates when the user moves 5 or more meters. This is problematic for my use cases.

这篇关于静止时,Apache Cordova geolocation.watchPosition()在iOS上超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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