Commit 41d72753 authored by Chris Scott's avatar Chris Scott

Implement Odometer feature to track distance travelled. getOdometer, resetOdometer

parent 0b91a967
......@@ -35,6 +35,8 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
public static final String ACTION_ON_STATIONARY = "addStationaryRegionListener";
public static final String ACTION_GET_LOCATIONS = "getLocations";
public static final String ACTION_SYNC = "sync";
public static final String ACTION_GET_ODOMETER = "getOdometer";
public static final String ACTION_RESET_ODOMETER = "resetOdometer";
private Boolean isEnabled = false;
private Boolean stopOnTerminate = false;
......@@ -53,6 +55,10 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
private CallbackContext syncCallback;
private CallbackContext getOdometerCallback;
private CallbackContext resetOdometerCallback;
public static boolean isActive() {
return gWebView != null;
}
......@@ -124,6 +130,20 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
event.putBoolean("request", true);
syncCallback = callbackContext;
EventBus.getDefault().post(event);
} else if (ACTION_GET_ODOMETER.equalsIgnoreCase(action)) {
result = true;
Bundle event = new Bundle();
event.putString("name", action);
event.putBoolean("request", true);
getOdometerCallback = callbackContext;
EventBus.getDefault().post(event);
} else if (ACTION_RESET_ODOMETER.equalsIgnoreCase(action)) {
result = true;
Bundle event = new Bundle();
event.putString("name", action);
event.putBoolean("request", true);
resetOdometerCallback = callbackContext;
EventBus.getDefault().post(event);
}
return result;
}
......@@ -271,6 +291,12 @@ public class CDVBackgroundGeolocation extends CordovaPlugin {
PluginResult result = new PluginResult(PluginResult.Status.IO_EXCEPTION, event.getString("message"));
runInBackground(syncCallback, result);
}
} else if (ACTION_GET_ODOMETER.equalsIgnoreCase(name)) {
PluginResult result = new PluginResult(PluginResult.Status.OK, event.getFloat("data"));
runInBackground(getOdometerCallback, result);
} else if (ACTION_RESET_ODOMETER.equalsIgnoreCase(name)) {
PluginResult result = new PluginResult(PluginResult.Status.OK);
runInBackground(resetOdometerCallback, result);
}
}
......
......@@ -22,5 +22,7 @@
- (void) getStationaryLocation:(CDVInvokedUrlCommand *)command;
- (void) getLocations:(CDVInvokedUrlCommand *)command;
- (void) sync:(CDVInvokedUrlCommand *)command;
- (void) getOdometer:(CDVInvokedUrlCommand *)command;
- (void) resetOdometer:(CDVInvokedUrlCommand *)command;
@end
......@@ -60,6 +60,17 @@
{
[bgGeo stop];
}
- (void) getOdometer:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble: bgGeo.odometer];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
- (void) resetOdometer:(CDVInvokedUrlCommand*)command
{
bgGeo.odometer = 0;
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
/**
* Change pace to moving/stopped
......
......@@ -4,6 +4,8 @@
@interface TSLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic) CLLocationDistance odometer;
- (void) configure:(NSDictionary*)config;
- (void) start;
- (void) stop;
......
......@@ -6,7 +6,7 @@
<dict>
<key>Headers/TSLocationManager.h</key>
<data>
uXAE4LxGF9ekkpUCvnRgTZf4wvM=
cDmPMOfd6jEG9Kg62Au0tnkrqWA=
</data>
<key>Info.plist</key>
<data>
......@@ -21,7 +21,7 @@
<dict>
<key>Headers/TSLocationManager.h</key>
<data>
uXAE4LxGF9ekkpUCvnRgTZf4wvM=
cDmPMOfd6jEG9Kg62Au0tnkrqWA=
</data>
<key>Modules/module.modulemap</key>
<data>
......
......@@ -136,7 +136,26 @@ module.exports = {
'sync',
[]);
},
/**
* Fetch current odometer value
*/
getOdometer: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'getOdometer',
[]);
},
/**
* Reset Odometer to 0
*/
resetOdometer: function(success, failure) {
exec(success || function() {},
failure || function() {},
'BackgroundGeoLocation',
'resetOdometer',
[]);
},
_setTimestamp: function(rs) {
// Transform timestamp to Date instance.
if (typeof(rs) === 'object') {
......
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