Commit 5481b52f authored by Chris Scott's avatar Chris Scott

Renamed a native var. added phonegap-method getStationaryLocation

parent 2bb78b13
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
NSDate *suspendedAt; NSDate *suspendedAt;
BOOL isAcquiringStationaryLocation; BOOL isAcquiringStationaryLocation;
CLLocation *bestStationaryLocation; CLLocation *stationaryLocation;
NSInteger stationaryLocationAttempts; NSInteger stationaryLocationAttempts;
CLCircularRegion *stationaryRegion; CLCircularRegion *stationaryRegion;
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
locationManager = [[CLLocationManager alloc] init]; locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self; locationManager.delegate = self;
bestStationaryLocation = nil; stationaryLocation = nil;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSuspend:) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSuspend:) name:UIApplicationDidEnterBackgroundNotification object:nil];
...@@ -152,6 +152,36 @@ ...@@ -152,6 +152,36 @@
} }
} }
} }
/**
* Fetches current stationaryLocation
*/
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command
{
NSLog(@"- CDVBackgroundGeoLocation getStationaryLocation");
NSMutableDictionary* returnInfo;
// Build a resultset for javascript callback.
CDVPluginResult* result = nil;
if (stationaryLocation) {
returnInfo = [NSMutableDictionary dictionaryWithCapacity:9];
NSNumber* timestamp = [NSNumber numberWithDouble:([stationaryLocation.timestamp timeIntervalSince1970] * 1000)];
[returnInfo setObject:timestamp forKey:@"timestamp"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.speed] forKey:@"velocity"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.verticalAccuracy] forKey:@"altitudeAccuracy"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.horizontalAccuracy] forKey:@"accuracy"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.course] forKey:@"heading"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.altitude] forKey:@"altitude"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.coordinate.latitude] forKey:@"latitude"];
[returnInfo setObject:[NSNumber numberWithDouble:stationaryLocation.coordinate.longitude] forKey:@"longitude"];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:returnInfo];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:NO];
}
[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
*/ */
...@@ -217,7 +247,7 @@ ...@@ -217,7 +247,7 @@
[locationManager stopUpdatingLocation]; [locationManager stopUpdatingLocation];
isAcquiringStationaryLocation = NO; isAcquiringStationaryLocation = NO;
[locationManager startMonitoringSignificantLocationChanges]; [locationManager startMonitoringSignificantLocationChanges];
[self startMonitoringStationaryRegion:bestStationaryLocation]; [self startMonitoringStationaryRegion:stationaryLocation];
} }
// Bail out if there's already a background-task in-effect. // Bail out if there's already a background-task in-effect.
...@@ -239,9 +269,9 @@ ...@@ -239,9 +269,9 @@
if (stationaryLocationAttempts == 5) { if (stationaryLocationAttempts == 5) {
return true; return true;
} }
if (bestStationaryLocation == nil || bestStationaryLocation.horizontalAccuracy > location.horizontalAccuracy) { if (stationaryLocation == nil || stationaryLocation.horizontalAccuracy > location.horizontalAccuracy) {
// store the location as the "best effort" // store the location as the "best effort"
bestStationaryLocation = location; stationaryLocation = location;
if (location.horizontalAccuracy <= 5.0) { if (location.horizontalAccuracy <= 5.0) {
return true; return true;
} }
...@@ -335,7 +365,7 @@ ...@@ -335,7 +365,7 @@
[locationManager startUpdatingLocation]; [locationManager startUpdatingLocation];
} else { } else {
// Crank up the GPS power temporarily to get a good fix on our current staionary location in order to set up region-monitoring. // Crank up the GPS power temporarily to get a good fix on our current staionary location in order to set up region-monitoring.
bestStationaryLocation = nil; stationaryLocation = nil;
isAcquiringStationaryLocation = YES; isAcquiringStationaryLocation = YES;
stationaryLocationAttempts = 0; stationaryLocationAttempts = 0;
locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.distanceFilter = kCLDistanceFilterNone;
......
/*** cordova.define("org.transistorsoft.cordova.background-geolocation.BackgroundGeoLocation", function(require, exports, module) {/***
* Custom Cordova Background GeoLocation plugin. Uses iOS native API * Custom Cordova Background GeoLocation plugin. Uses iOS native API
* @author <chris@transistorsoft.com> * @author <chris@transistorsoft.com>
* @author <brian@briansamson.com> * @author <brian@briansamson.com>
...@@ -78,5 +78,15 @@ module.exports = { ...@@ -78,5 +78,15 @@ module.exports = {
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'setConfig', 'setConfig',
[config]); [config]);
} },
}; /**
\ No newline at end of file * Returns current stationaryLocation if available. null if not
*/
getStationaryLocation: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'getStationaryLocation',
[]);
}
};});
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