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