Apache Cordova geolocation.watchPosition() times o

2019-03-21 16:34发布

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.

1条回答
趁早两清
2楼-- · 2019-03-21 16:57

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.

查看更多
登录 后发表回答