Commit 2d69f9e5 authored by Chris Scott's avatar Chris Scott

Merge pull request #8 from christocracy/android

Android
parents 34a0297a 5244f8b2
BackgroundGeoLocation
==============================
Cross-platform background geolocation for Cordova / PhoneGap.
Cross-platform background geolocation for Cordova / PhoneGap with battery-saving "circular region monitoring" and "stop detection".
Follows the [Cordova Plugin spec](https://github.com/apache/cordova-plugman/blob/master/plugin_spec.md), so that it works with [Plugman](https://github.com/apache/cordova-plugman).
......@@ -20,7 +20,7 @@ The plugin creates the object `window.plugins.backgroundGeoLocation` with the me
```
phonegap plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git
cordova plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git
```
A full example could be:
......@@ -70,7 +70,10 @@ A full example could be:
// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http
authToken: 'user_secret_auth_token', // <-- only required for Android; ios allows javascript callbacks for your http
params: { // HTTP POST params sent to your server when persisting locations.
auth_token: 'user_secret_auth_token'
foo: 'bar'
},
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
......@@ -98,7 +101,7 @@ When the plugin detects your user has moved beyond his stationary-region, it eng
## iOS and Android
The plugin works best with iOS but Android is currently under heavy development and coming along well with features being ported from iOS. Those are the only two supported platforms but I foresee a Windows Phone version once I get a client who desires that.
The plugin works with iOS and Android
### Config
......@@ -160,7 +163,6 @@ Compare now background-geolocation in the scope of a city. In this image, the l
![distanceFilter at city scale](/distance-filter-city.png "distanceFilter at city scale")
## Licence ##
The MIT License
......
......@@ -91,7 +91,10 @@ var app = {
// BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http
authToken: 'user_secret_auth_token', // <-- only required for Android; ios allows javascript callbacks for your http
params: { // HTTP POST params sent to your server when persisting locations.
auth_token: 'user_secret_auth_token'
foo: 'bar'
},
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
......
......@@ -23,8 +23,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private Boolean isEnabled = false;
private String authToken;
private String url;
private String params;
private String stationaryRadius = "30";
private String desiredAccuracy = "100";
private String distanceFilter = "30";
......@@ -38,12 +38,12 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
result = true;
if (authToken == null || url == null) {
if (params == null || url == null) {
callbackContext.error("Call configure before calling start");
} else {
callbackContext.success();
updateServiceIntent.putExtra("authToken", authToken);
updateServiceIntent.putExtra("url", url);
updateServiceIntent.putExtra("params", params);
updateServiceIntent.putExtra("stationaryRadius", stationaryRadius);
updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("distanceFilter", distanceFilter);
......@@ -62,9 +62,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
result = true;
try {
// [authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
this.authToken = data.getString(0);
// [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
this.params = data.getString(0);
this.url = data.getString(1);
this.stationaryRadius = data.getString(2);
this.distanceFilter = data.getString(3);
......
This diff is collapsed.
var exec = require("cordova/exec");
module.exports = {
configure: function(success, failure, config) {
var authToken = config.authToken || 'BackgroundGeoLocation_auth_token',
var params = JSON.stringify(config.params || {}),
url = config.url || 'BackgroundGeoLocation_url',
stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds
locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds
desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100; // meters
debug = config.debug || false;
......@@ -13,7 +13,7 @@ module.exports = {
failure || function() {},
'BackgroundGeoLocation',
'configure',
[authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
[params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
},
start: function(success, failure, config) {
exec(success || 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