Ali*_*iss 3 geolocation ios cordova cordova-plugins
当使用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});
);
Run Code Online (Sandbox Code Playgroud)
切换到getCurrentPosition()也无效,因为除非GPS被连续轮询,否则精度不会达到并保持在农业用途所需的水平.
此问题不会出现在Android上.
解决方案是直接修改CDVLocation.m以删除distanceFilter.或者更具体地说:
if (enableHighAccurary) {
// snipped
// self.locationManager.distanceFilter = 5;// original, causes problems standing still
self.locationManager.distanceFilter = kCLDistanceFilterNone;
//snipped
} else {
Run Code Online (Sandbox Code Playgroud)
从代码中的评论来看,这是一个有意识的决定,以节省电池的名义,只在用户移动5米或更多米时才发送更新.这对我的用例来说是个问题.