Commit 10402f75 authored by Chris Scott's avatar Chris Scott

Add setConfig method to allow modification of geolocation params in real-time

parent e09a4fb8
......@@ -14,6 +14,7 @@
- (void) finish:(CDVInvokedUrlCommand*)command;
- (void) onPaceChange:(CDVInvokedUrlCommand*)command;
- (void) setStationaryRadius:(CDVInvokedUrlCommand*)command;
- (void) setDesiredAccuracy:(CDVInvokedUrlCommand*)command;
- (void) setDistanceFilter:(CDVInvokedUrlCommand*)command;
- (void) sync:(CLLocation*)location;
......
......@@ -25,8 +25,8 @@
CLCircularRegion *myRegion;
NSInteger stationaryRadius;
NSInteger distanceFilter;
NSInteger locationTimeout;
NSInteger desiredAccuracy;
NSInteger locationTimeout;
}
- (void)pluginInitialize
......@@ -65,22 +65,6 @@
// Set a movement threshold for new events.
locationManager.activityType = CLActivityTypeOther;
locationManager.pausesLocationUpdatesAutomatically = YES;
switch (desiredAccuracy) {
case 1000:
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
break;
case 100:
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
break;
case 10:
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
break;
case 0:
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
break;
}
locationManager.distanceFilter = distanceFilter; // meters
myRegion = nil;
......@@ -140,6 +124,11 @@
stationaryRadius = [[command.arguments objectAtIndex: 0] intValue];
NSLog(@"- CDVBackgroundGeoLocation setStationaryRadius %d", stationaryRadius);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
......@@ -152,11 +141,32 @@
distanceFilter = [[command.arguments objectAtIndex: 0] intValue];
NSLog(@"- CDVBackgroundGeoLocation setDistanceFilter %d", distanceFilter);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Change stationary radius
*/
- (void) setDesiredAccuracy:(CDVInvokedUrlCommand *)command
{
desiredAccuracy = [[command.arguments objectAtIndex: 0] intValue];
NSLog(@"- CDVBackgroundGeoLocation setDesiredAccuracy %d", desiredAccuracy);
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground) {
[self setPace:isMoving];
}
CDVPluginResult* result = nil;
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Called by js to signify the end of a background-geolocation event
*/
......@@ -283,8 +293,30 @@
*/
- (void)setPace:(BOOL)value
{
NSLog(@"- CDVBackgroundGeoLocation setPace %d", value);
isMoving = value;
// When stationaryRadius is 0, don't use sig.changes -- keep GPS on constantly.
isMoving = (stationaryRadius == 0) ? YES : value;
NSLog(@"- CDVBackgroundGeoLocation setPace");
NSLog(@" isMoving %d", isMoving);
NSLog(@" desiredAccuracy: %d", desiredAccuracy);
NSLog(@" distanceFilter: %d", distanceFilter);
NSLog(@" stationaryRadius: %d", stationaryRadius);
switch (desiredAccuracy) {
case 1000:
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
break;
case 100:
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
break;
case 10:
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
break;
case 0:
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
break;
}
if (myRegion != nil) {
[locationManager stopMonitoringForRegion:myRegion];
myRegion = nil;
......
......@@ -66,6 +66,19 @@ module.exports = {
'onPaceChange',
[isMoving]);
},
/**
* @param {Integer} stationaryRadius
* @param {Integer} desiredAccuracy
* @param {Integer} distanceFilter
* @param {Integer} timeout
*/
setConfig: function(success, failure, config) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'setConfig',
[config]);
},
setStationaryRadius: function(value, success, failure) {
exec(success || function() {},
failure || function() {},
......@@ -73,6 +86,13 @@ module.exports = {
'setStationaryRadius',
[value]);
},
setDesiredAccuracy: function(value, success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'setDesiredAccuracy',
[value]);
},
setDistanceFilter: function(value, success, failure) {
exec(success || function() {},
failure || function() {},
......
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