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

Merge pull request #8 from christocracy/android

Android
parents 34a0297a 5244f8b2
BackgroundGeoLocation 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). 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 ...@@ -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: A full example could be:
...@@ -70,7 +70,10 @@ A full example could be: ...@@ -70,7 +70,10 @@ A full example could be:
// BackgroundGeoLocation is highly configurable. // BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, { bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http 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, desiredAccuracy: 10,
stationaryRadius: 20, stationaryRadius: 20,
distanceFilter: 30, distanceFilter: 30,
...@@ -98,7 +101,7 @@ When the plugin detects your user has moved beyond his stationary-region, it eng ...@@ -98,7 +101,7 @@ When the plugin detects your user has moved beyond his stationary-region, it eng
## iOS and Android ## 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 ### Config
...@@ -160,7 +163,6 @@ Compare now background-geolocation in the scope of a city. In this image, the l ...@@ -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") ![distanceFilter at city scale](/distance-filter-city.png "distanceFilter at city scale")
## Licence ## ## Licence ##
The MIT License The MIT License
......
...@@ -91,7 +91,10 @@ var app = { ...@@ -91,7 +91,10 @@ var app = {
// BackgroundGeoLocation is highly configurable. // BackgroundGeoLocation is highly configurable.
bgGeo.configure(callbackFn, failureFn, { bgGeo.configure(callbackFn, failureFn, {
url: 'http://only.for.android.com/update_location.json', // <-- only required for Android; ios allows javascript callbacks for your http 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, desiredAccuracy: 10,
stationaryRadius: 20, stationaryRadius: 20,
distanceFilter: 30, distanceFilter: 30,
......
...@@ -23,8 +23,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -23,8 +23,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private Boolean isEnabled = false; private Boolean isEnabled = false;
private String authToken;
private String url; private String url;
private String params;
private String stationaryRadius = "30"; private String stationaryRadius = "30";
private String desiredAccuracy = "100"; private String desiredAccuracy = "100";
private String distanceFilter = "30"; private String distanceFilter = "30";
...@@ -38,12 +38,12 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -38,12 +38,12 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) { if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
result = true; result = true;
if (authToken == null || url == null) { if (params == null || url == null) {
callbackContext.error("Call configure before calling start"); callbackContext.error("Call configure before calling start");
} else { } else {
callbackContext.success(); callbackContext.success();
updateServiceIntent.putExtra("authToken", authToken);
updateServiceIntent.putExtra("url", url); updateServiceIntent.putExtra("url", url);
updateServiceIntent.putExtra("params", params);
updateServiceIntent.putExtra("stationaryRadius", stationaryRadius); updateServiceIntent.putExtra("stationaryRadius", stationaryRadius);
updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy); updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("distanceFilter", distanceFilter); updateServiceIntent.putExtra("distanceFilter", distanceFilter);
...@@ -62,9 +62,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -62,9 +62,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) { } else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
result = true; result = true;
try { try {
// [authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]); // [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
this.params = data.getString(0);
this.authToken = data.getString(0);
this.url = data.getString(1); this.url = data.getString(1);
this.stationaryRadius = data.getString(2); this.stationaryRadius = data.getString(2);
this.distanceFilter = data.getString(3); this.distanceFilter = data.getString(3);
......
This diff is collapsed.
var exec = require("cordova/exec"); var exec = require("cordova/exec");
module.exports = { module.exports = {
configure: function(success, failure, config) { configure: function(success, failure, config) {
var authToken = config.authToken || 'BackgroundGeoLocation_auth_token', var params = JSON.stringify(config.params || {}),
url = config.url || 'BackgroundGeoLocation_url', url = config.url || 'BackgroundGeoLocation_url',
stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
...@@ -13,7 +13,7 @@ module.exports = { ...@@ -13,7 +13,7 @@ module.exports = {
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'configure', 'configure',
[authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]); [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
}, },
start: function(success, failure, config) { start: function(success, failure, config) {
exec(success || function() {}, 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