Commit f4874a21 authored by Chris Scott's avatar Chris Scott

Implement automatic distanceFilter calculation based upon speed

parent d6353953
...@@ -286,6 +286,25 @@ ...@@ -286,6 +286,25 @@
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[self sync:newLocation]; [self sync:newLocation];
}]; }];
// Adjust distanceFilter incrementally based upon current velocity
if (isMoving)
{
float newDistanceFilter = distanceFilter;
// sanity-check obvious high speed error.
if (newLocation.speed > 100) {
return;
}
if (newLocation.speed > 5.0) {
newDistanceFilter = [self calculateDistanceFilter:newLocation.speed];
}
if (newDistanceFilter != locationManager.distanceFilter) {
NSLog(@"- CDVBackgroundGeoLocation updated distanceFilter, new: %f, old: %f", newDistanceFilter, locationManager.distanceFilter);
[locationManager stopUpdatingLocation];
locationManager.distanceFilter = newDistanceFilter;
[locationManager startUpdatingLocation];
}
}
} }
-(BOOL) isBestStationaryLocation:(CLLocation*)location { -(BOOL) isBestStationaryLocation:(CLLocation*)location {
stationaryLocationAttempts++; stationaryLocationAttempts++;
...@@ -308,7 +327,7 @@ ...@@ -308,7 +327,7 @@
*/ */
-(void) sync:(CLLocation*)location -(void) sync:(CLLocation*)location
{ {
NSLog(@" %f,%f", location.coordinate.latitude, location.coordinate.longitude); NSLog(@" position: %f,%f, speed: %f", location.coordinate.latitude, location.coordinate.longitude, location.speed);
if (isDebugging) { if (isDebugging) {
AudioServicesPlaySystemSound (locationSyncSound); AudioServicesPlaySystemSound (locationSyncSound);
} }
...@@ -332,6 +351,14 @@ ...@@ -332,6 +351,14 @@
[self.commandDelegate sendPluginResult:result callbackId:syncCallbackId]; [self.commandDelegate sendPluginResult:result callbackId:syncCallbackId];
} }
/**
* Calculates distanceFilter by rounding speed to nearest 5 and multiplying by 10.
*/
-(float) calculateDistanceFilter:(float)velocity
{
return (5.0 * floorf(velocity / 5.0 + 0.5f)) * 10;
}
- (void) stopBackgroundTask - (void) stopBackgroundTask
{ {
UIApplication *app = [UIApplication sharedApplication]; UIApplication *app = [UIApplication sharedApplication];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment