Commit bfcb33d6 authored by Chris Scott's avatar Chris Scott

Docs

parent 705bf5b3
...@@ -195,13 +195,13 @@ Keep in mind that it is **not** possible to use ```start()``` at the ```pause``` ...@@ -195,13 +195,13 @@ Keep in mind that it is **not** possible to use ```start()``` at the ```pause```
## Methods ## Methods
#####`configure(locationCallback, failureCallback, config)` ####`configure(locationCallback, failureCallback, config)`
Configures the plugin's parameters (@see following [Config](https://github.com/christocracy/cordova-background-geolocation/blob/edge/README.md#config) section for accepted ```config``` params. The ```locationCallback``` will be executed each time a new Geolocation is recorded and provided with the following parameters: Configures the plugin's parameters (@see following [Config](https://github.com/christocracy/cordova-background-geolocation/blob/edge/README.md#config) section for accepted ```config``` params. The ```locationCallback``` will be executed each time a new Geolocation is recorded and provided with the following parameters:
#######`@param {Object} location` The Location data ######`@param {Object} location` The Location data
`{"coords":{"latitude":45.5192735,"longitude":-73.6168883,"accuracy":10,"speed":0,"heading":0,"altitude":0},"timestamp":"2015-05-27T18:26:44Z"}` `{"coords":{"latitude":45.5192735,"longitude":-73.6168883,"accuracy":10,"speed":0,"heading":0,"altitude":0},"timestamp":"2015-05-27T18:26:44Z"}`
#######`@param {Integer} taskId` The taskId used to send to bgGeo.finish(taskId) in order to signal completion of your callbackFn ######`@param {Integer} taskId` The taskId used to send to bgGeo.finish(taskId) in order to signal completion of your callbackFn
#####`setConfig(successFn, failureFn, config)` #####`setConfig(successFn, failureFn, config)`
Reconfigure plugin's configuration (@see followign ##Config## section for accepted ```config``` params. **NOTE** The plugin will continue to send recorded Geolocation to the ```locationCallback``` you provided to ```configure``` method -- use this method only to change configuration params (eg: ```distanceFilter```, ```stationaryRadius```, etc). Reconfigure plugin's configuration (@see followign ##Config## section for accepted ```config``` params. **NOTE** The plugin will continue to send recorded Geolocation to the ```locationCallback``` you provided to ```configure``` method -- use this method only to change configuration params (eg: ```distanceFilter```, ```stationaryRadius```, etc).
...@@ -213,7 +213,7 @@ bgGeo.setConfig(function(){}, function(){}, { ...@@ -213,7 +213,7 @@ bgGeo.setConfig(function(){}, function(){}, {
}); });
``` ```
#####`start(successFn, failureFn)` ####`start(successFn, failureFn)`
Enable background geolocation tracking. Enable background geolocation tracking.
...@@ -221,7 +221,7 @@ Enable background geolocation tracking. ...@@ -221,7 +221,7 @@ Enable background geolocation tracking.
bgGeo.start() bgGeo.start()
``` ```
#####`stop(successFn, failureFn)` ####`stop(successFn, failureFn)`
Disable background geolocation tracking. Disable background geolocation tracking.
...@@ -229,7 +229,7 @@ Disable background geolocation tracking. ...@@ -229,7 +229,7 @@ Disable background geolocation tracking.
bgGeo.stop(); bgGeo.stop();
``` ```
#####`changePace(enabled, successFn, failureFn)` ####`changePace(enabled, successFn, failureFn)`
Initiate or cancel immediate background tracking. When set to ```true```, the plugin will begin aggressively tracking the devices Geolocation, bypassing stationary monitoring. If you were making a "Jogging" application, this would be your [Start Workout] button to immediately begin GPS tracking. Send ```false``` to disable aggressive GPS monitoring and return to stationary-monitoring mode. Initiate or cancel immediate background tracking. When set to ```true```, the plugin will begin aggressively tracking the devices Geolocation, bypassing stationary monitoring. If you were making a "Jogging" application, this would be your [Start Workout] button to immediately begin GPS tracking. Send ```false``` to disable aggressive GPS monitoring and return to stationary-monitoring mode.
``` ```
...@@ -237,7 +237,7 @@ bgGeo.changePace(true); // <-- Aggressive GPS monitoring immediately engaged. ...@@ -237,7 +237,7 @@ bgGeo.changePace(true); // <-- Aggressive GPS monitoring immediately engaged.
bgGeo.changePace(false); // <-- Disable aggressive GPS monitoring. Engages stationary-mode. bgGeo.changePace(false); // <-- Disable aggressive GPS monitoring. Engages stationary-mode.
``` ```
#####`onStationary(callbackFn, failureFn)` ####`onStationary(callbackFn, failureFn)`
Your ```callbackFn``` will be executed each time the device has entered stationary-monitoring mode. The ```callbackFn``` will be provided with a ```Location``` object as the 1st param, with the usual params (```latitude, longitude, accuracy, speed, bearing, altitude```), in addition to a ```taskId``` used to signal that your callback is finished. Your ```callbackFn``` will be executed each time the device has entered stationary-monitoring mode. The ```callbackFn``` will be provided with a ```Location``` object as the 1st param, with the usual params (```latitude, longitude, accuracy, speed, bearing, altitude```), in addition to a ```taskId``` used to signal that your callback is finished.
``` ```
...@@ -251,13 +251,13 @@ bgGeo.onStationary(function(location, taskId) { ...@@ -251,13 +251,13 @@ bgGeo.onStationary(function(location, taskId) {
}); });
``` ```
#####`addGeofence(config, callbackFn, failureFn)` ####`addGeofence(config, callbackFn, failureFn)`
Adds a geofence to be monitored by the native plugin. Monitoring of a geofence is halted after a crossing occurs. The `config` object accepts the following params. Adds a geofence to be monitored by the native plugin. Monitoring of a geofence is halted after a crossing occurs. The `config` object accepts the following params.
#######`@config {String} identifier The name of your geofence, eg: "Home", "Office" ######`@config {String} identifier The name of your geofence, eg: "Home", "Office"
#######`@config {Float} radius The radius (meters) of the geofence. In practice, you should make this >= 100 meters. ######`@config {Float} radius The radius (meters) of the geofence. In practice, you should make this >= 100 meters.
#######`@config {Float} latitude Latitude of the center-point of the circular geofence. ######`@config {Float} latitude Latitude of the center-point of the circular geofence.
#######`@config {Float} longitude Longitude of the center-point of the circular geofence. ######`@config {Float} longitude Longitude of the center-point of the circular geofence.
``` ```
bgGeo.addGeofence({ bgGeo.addGeofence({
...@@ -272,11 +272,11 @@ bgGeo.addGeofence({ ...@@ -272,11 +272,11 @@ bgGeo.addGeofence({
}); });
``` ```
#####`onGeofence(callbackFn)` ####`onGeofence(callbackFn)`
Adds a geofence event-listener. Your supplied callback will be called when any monitored geofence crossing occurs. The `callbackFn` will be provided the following parameters: Adds a geofence event-listener. Your supplied callback will be called when any monitored geofence crossing occurs. The `callbackFn` will be provided the following parameters:
#######`@param {String} identifier The name of the geofence which generated the crossing event, eg: "Home" ######`@param {String} identifier The name of the geofence which generated the crossing event, eg: "Home"
#######`@param {Integer} taskId The background taskId which you must send back to the native plugin via `bgGeo.finish(taskId)` in order to signal that your callback is complete. ######`@param {Integer} taskId The background taskId which you must send back to the native plugin via `bgGeo.finish(taskId)` in order to signal that your callback is complete.
``` ```
bgGeo.onGeofence(function(identifier, taskId) { bgGeo.onGeofence(function(identifier, taskId) {
...@@ -289,7 +289,7 @@ bgGeo.onGeofence(function(identifier, taskId) { ...@@ -289,7 +289,7 @@ bgGeo.onGeofence(function(identifier, taskId) {
}); });
``` ```
#####`getLocations(callbackFn, failureFn)` ####`getLocations(callbackFn, failureFn)`
Fetch all the locations currently stored in native plugin's SQLite database. Your ```callbackFn`` will receive an ```Array``` of locations in the 1st parameter. Eg: Fetch all the locations currently stored in native plugin's SQLite database. Your ```callbackFn`` will receive an ```Array``` of locations in the 1st parameter. Eg:
``` ```
...@@ -298,7 +298,7 @@ Fetch all the locations currently stored in native plugin's SQLite database. Yo ...@@ -298,7 +298,7 @@ Fetch all the locations currently stored in native plugin's SQLite database. Yo
}); });
``` ```
#####`sync(callbackFn, failureFn)` ####`sync(callbackFn, failureFn)`
If the plugin is configured for HTTP with an ```#url``` and ```#autoSync: false```, this method will initiate POSTing the locations currently stored in the native SQLite database to your configured ```#url```. All records in the database will be DELETED. If you configured ```batchSync: true```, all the locations will be sent to your server in a single HTTP POST request, otherwise the plugin will create execute an HTTP post for **each** location in the database (REST-style). Your ```callbackFn``` will be executed and provided with an Array of all the locations from the SQLite database. If the plugin failed to sync to your server (possibly because of no network connection), the ```failureFn``` will be called with an ```errorMessage```. If you are **not** using the HTTP features, ```sync``` is the only way to clear the native SQLite datbase. Eg: If the plugin is configured for HTTP with an ```#url``` and ```#autoSync: false```, this method will initiate POSTing the locations currently stored in the native SQLite database to your configured ```#url```. All records in the database will be DELETED. If you configured ```batchSync: true```, all the locations will be sent to your server in a single HTTP POST request, otherwise the plugin will create execute an HTTP post for **each** location in the database (REST-style). Your ```callbackFn``` will be executed and provided with an Array of all the locations from the SQLite database. If the plugin failed to sync to your server (possibly because of no network connection), the ```failureFn``` will be called with an ```errorMessage```. If you are **not** using the HTTP features, ```sync``` is the only way to clear the native SQLite datbase. Eg:
...@@ -312,7 +312,7 @@ If the plugin is configured for HTTP with an ```#url``` and ```#autoSync: false` ...@@ -312,7 +312,7 @@ If the plugin is configured for HTTP with an ```#url``` and ```#autoSync: false`
``` ```
#####`getOdometer(callbackFn, failureFn)` ####`getOdometer(callbackFn, failureFn)`
The plugin constantly tracks distance travelled. To fetch the current **odometer** reading: The plugin constantly tracks distance travelled. To fetch the current **odometer** reading:
...@@ -322,7 +322,7 @@ The plugin constantly tracks distance travelled. To fetch the current **odomete ...@@ -322,7 +322,7 @@ The plugin constantly tracks distance travelled. To fetch the current **odomete
}); });
``` ```
#####`resetOdometer(callbackFn, failureFn)` ####`resetOdometer(callbackFn, failureFn)`
Reset the **odometer** to zero. The plugin never automatically resets the odometer so it's up to you to reset it as desired. Reset the **odometer** to zero. The plugin never automatically resets the odometer so it's up to you to reset it as desired.
...@@ -330,7 +330,7 @@ Reset the **odometer** to zero. The plugin never automatically resets the odome ...@@ -330,7 +330,7 @@ Reset the **odometer** to zero. The plugin never automatically resets the odome
Use the following config-parameters with the #configure method: Use the following config-parameters with the #configure method:
#####`@param {Boolean} debug` ####`@param {Boolean} debug`
When enabled, the plugin will emit sounds for life-cycle events of background-geolocation! **NOTE iOS**: In addition, you must manually enable the *Audio and Airplay* background mode in *Background Capabilities* to hear these debugging sounds. When enabled, the plugin will emit sounds for life-cycle events of background-geolocation! **NOTE iOS**: In addition, you must manually enable the *Audio and Airplay* background mode in *Background Capabilities* to hear these debugging sounds.
...@@ -342,18 +342,18 @@ When enabled, the plugin will emit sounds for life-cycle events of background-ge ...@@ -342,18 +342,18 @@ When enabled, the plugin will emit sounds for life-cycle events of background-ge
![Enable Background Audio](/enable-background-audio.png "Enable Background Audio") ![Enable Background Audio](/enable-background-audio.png "Enable Background Audio")
#####`@param {Integer} desiredAccuracy [0, 10, 100, 1000] in meters` ####`@param {Integer} desiredAccuracy [0, 10, 100, 1000] in meters`
Specify the desired-accuracy of the geolocation system with 1 of 4 values, ```0, 10, 100, 1000``` where ```0``` means HIGHEST POWER, HIGHEST ACCURACY and ```1000``` means LOWEST POWER, LOWEST ACCURACY Specify the desired-accuracy of the geolocation system with 1 of 4 values, ```0, 10, 100, 1000``` where ```0``` means HIGHEST POWER, HIGHEST ACCURACY and ```1000``` means LOWEST POWER, LOWEST ACCURACY
- [Android](https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#PRIORITY_BALANCED_POWER_ACCURACY) - [Android](https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#PRIORITY_BALANCED_POWER_ACCURACY)
- [iOS](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy) - [iOS](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy)
#####`@param {Integer} stationaryRadius (meters)` ####`@param {Integer} stationaryRadius (meters)`
When stopped, the minimum distance the device must move beyond the stationary location for aggressive background-tracking to engage. Note, since the plugin uses iOS significant-changes API, the plugin cannot detect the exact moment the device moves out of the stationary-radius. In normal conditions, it can take as much as 3 city-blocks to 1/2 km before staionary-region exit is detected. When stopped, the minimum distance the device must move beyond the stationary location for aggressive background-tracking to engage. Note, since the plugin uses iOS significant-changes API, the plugin cannot detect the exact moment the device moves out of the stationary-radius. In normal conditions, it can take as much as 3 city-blocks to 1/2 km before staionary-region exit is detected.
#####`@param {Integer} distanceFilter` ####`@param {Integer} distanceFilter`
The minimum distance (measured in meters) a device must move horizontally before an update event is generated. @see [Apple docs](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/distanceFilter). However, #distanceFilter is elastically auto-calculated by the plugin: When speed increases, #distanceFilter increases; when speed decreases, so does distanceFilter. The minimum distance (measured in meters) a device must move horizontally before an update event is generated. @see [Apple docs](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/distanceFilter). However, #distanceFilter is elastically auto-calculated by the plugin: When speed increases, #distanceFilter increases; when speed decreases, so does distanceFilter.
...@@ -407,34 +407,36 @@ If you **don't** configure the optional HTTP feature, the only way to delete the ...@@ -407,34 +407,36 @@ If you **don't** configure the optional HTTP feature, the only way to delete the
}); });
``` ```
#### HTTP Features ### HTTP Features
#####`@param {String} url` ####`@param {String} url`
Your server url where you wish to HTTP POST location data to. Your server url where you wish to HTTP POST location data to.
#####`@param {String} batchSync [false]` ####`@param {String} batchSync [false]`
Default is ```false```. If you've enabled HTTP feature by configuring an ```#url```, ```batchSync: true``` will POST all the locations currently stored in native SQLite datbase to your server in a single HTTP POST request. With ```batchSync: false```, an HTTP POST request will be initiated for **each** location in database. Default is ```false```. If you've enabled HTTP feature by configuring an ```#url```, ```batchSync: true``` will POST all the locations currently stored in native SQLite datbase to your server in a single HTTP POST request. With ```batchSync: false```, an HTTP POST request will be initiated for **each** location in database.
#####`@param {String} autoSync [true]` ####`@param {String} autoSync [true]`
Default is ```true```. If you've enabeld HTTP feature by configuring an ```#url```, the plugin will attempt to HTTP POST each location to your server **as it is recorded**. If you set ```autoSync: false```, it's up to you to **manually** execute the ```#sync``` method to initate the HTTP POST (**NOTE** The plugin will continue to persist **every** recorded location in the SQLite database until you execute ```#sync```). Default is ```true```. If you've enabeld HTTP feature by configuring an ```#url```, the plugin will attempt to HTTP POST each location to your server **as it is recorded**. If you set ```autoSync: false```, it's up to you to **manually** execute the ```#sync``` method to initate the HTTP POST (**NOTE** The plugin will continue to persist **every** recorded location in the SQLite database until you execute ```#sync```).
#####`@param {Object} params` ####`@param {Object} params`
Optional HTTP params sent along in HTTP request to above ```#url```. Optional HTTP params sent along in HTTP request to above ```#url```.
#####`@param {Object} headers` ####`@param {Object} headers`
Optional HTTP params sent along in HTTP request to above ```#url```. Optional HTTP params sent along in HTTP request to above ```#url```.
#####`@param {Integer} maxDaysToPersist` ####`@param {Integer} maxDaysToPersist`
Maximum number of days to store a geolocation in plugin's SQLite database when your server fails to respond with ```HTTP 200 OK```. The plugin will continue attempting to sync with your server until ```maxDaysToPersist``` when it will give up and remove the location from the database. Maximum number of days to store a geolocation in plugin's SQLite database when your server fails to respond with ```HTTP 200 OK```. The plugin will continue attempting to sync with your server until ```maxDaysToPersist``` when it will give up and remove the location from the database.
Both iOS and Android can send the Geolocation to your server simply by configuring an ```#url``` in addition to optional ```#headers``` and ```#params```. This is the preferred way to send the Geolocation to your server, rather than doing it yourself with Ajax in your javascript. Both iOS and Android can send the Geolocation to your server simply by configuring an ```#url``` in addition to optional ```#headers``` and ```#params```. This is the preferred way to send the Geolocation to your server, rather than doing it yourself with Ajax in your javascript.
#### Sample HTTP Request arriving at your server
``` ```
bgGeo.configure(callbackFn, failureFn, { bgGeo.configure(callbackFn, failureFn, {
. .
...@@ -498,7 +500,7 @@ No Post Params. ...@@ -498,7 +500,7 @@ No Post Params.
### Android Config ### Android Config
#####`@param {Integer millis} locationUpdateInterval` ####`@param {Integer millis} locationUpdateInterval`
Set the desired interval for active location updates, in milliseconds. Set the desired interval for active location updates, in milliseconds.
...@@ -508,7 +510,7 @@ This interval is inexact. You may not receive updates at all (if no location sou ...@@ -508,7 +510,7 @@ This interval is inexact. You may not receive updates at all (if no location sou
Applications with only the coarse location permission may have their interval silently throttled. Applications with only the coarse location permission may have their interval silently throttled.
#####`@param {Integer millis} fastestLocationUpdateInterval` ####`@param {Integer millis} fastestLocationUpdateInterval`
Explicitly set the fastest interval for location updates, in milliseconds. Explicitly set the fastest interval for location updates, in milliseconds.
...@@ -527,19 +529,19 @@ If ```#fastestLocationUpdateInterval``` is set slower than ```#locationUpdateInt ...@@ -527,19 +529,19 @@ If ```#fastestLocationUpdateInterval``` is set slower than ```#locationUpdateInt
======== ========
An interval of 0 is allowed, but not recommended, since location updates may be extremely fast on future implementations. An interval of 0 is allowed, but not recommended, since location updates may be extremely fast on future implementations.
#####`@param {Integer millis} activityRecognitionInterval` ####`@param {Integer millis} activityRecognitionInterval`
the desired time between activity detections. Larger values will result in fewer activity detections while improving battery life. A value of 0 will result in activity detections at the fastest possible rate. the desired time between activity detections. Larger values will result in fewer activity detections while improving battery life. A value of 0 will result in activity detections at the fastest possible rate.
#####`@param {Integer minutes} stopTimeout` ####`@param {Integer minutes} stopTimeout`
The number of miutes to wait before turning off the GPS after the ActivityRecognition System (ARS) detects the device is ```STILL``` (defaults to 0, no timeout). If you don't set a value, the plugin is eager to turn off the GPS ASAP. An example use-case for this configuration is to delay GPS OFF while in a car waiting at a traffic light. The number of miutes to wait before turning off the GPS after the ActivityRecognition System (ARS) detects the device is ```STILL``` (defaults to 0, no timeout). If you don't set a value, the plugin is eager to turn off the GPS ASAP. An example use-case for this configuration is to delay GPS OFF while in a car waiting at a traffic light.
#####`@param {Boolean} forceReload` ####`@param {Boolean} forceReload`
If the user closes the application while the background-tracking has been started, location-tracking will continue on if ```stopOnTerminate: false```. You may choose to force the foreground application to reload (since this is where your Javascript runs) by setting ```foreceReload: true```. This will guarantee that locations are always sent to your Javascript callback (**WARNING** possibly disruptive to user). If the user closes the application while the background-tracking has been started, location-tracking will continue on if ```stopOnTerminate: false```. You may choose to force the foreground application to reload (since this is where your Javascript runs) by setting ```foreceReload: true```. This will guarantee that locations are always sent to your Javascript callback (**WARNING** possibly disruptive to user).
#####`@param {Boolean} startOnBoot` ####`@param {Boolean} startOnBoot`
Set to ```true``` to start the background-service whenever the device boots. Unless you configure the plugin to ```forceReload``` (ie: boot your app), you should configure the plugin's HTTP features so it can POST to your server in "headless" mode. Set to ```true``` to start the background-service whenever the device boots. Unless you configure the plugin to ```forceReload``` (ie: boot your app), you should configure the plugin's HTTP features so it can POST to your server in "headless" mode.
...@@ -547,19 +549,19 @@ Set to ```true``` to start the background-service whenever the device boots. Un ...@@ -547,19 +549,19 @@ Set to ```true``` to start the background-service whenever the device boots. Un
### iOS Config ### iOS Config
#####`@param {Boolean} disableElasticity [false]` ####`@param {Boolean} disableElasticity [false]`
Defaults to ```false```. Set ```true``` to disable automatic speed-based ```#distanceFilter``` elasticity. eg: When device is moving at highway speeds, locations are returned at ~ 1 / km. Defaults to ```false```. Set ```true``` to disable automatic speed-based ```#distanceFilter``` elasticity. eg: When device is moving at highway speeds, locations are returned at ~ 1 / km.
#####`@param {String} activityType [AutomotiveNavigation, OtherNavigation, Fitness, Other]` ####`@param {String} activityType [AutomotiveNavigation, OtherNavigation, Fitness, Other]`
Presumably, this affects ios GPS algorithm. See [Apple docs](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType) for more information Presumably, this affects ios GPS algorithm. See [Apple docs](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType) for more information
### WP8 Config ### WP8 Config
#####`{Integer [0, 10, 100, 1000]} desiredAccuracy` ####`{Integer [0, 10, 100, 1000]} desiredAccuracy`
###### Windows Phone ##### Windows Phone
The underlying GeoLocator you can choose to use 'DesiredAccuracy' or 'DesiredAccuracyInMeters'. Since this plugins default configuration accepts meters, the default desiredAccuracy is mapped to the Windows Phone DesiredAccuracyInMeters leaving the DesiredAccuracy enum empty. For more info see the [MS docs](http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.desiredaccuracyinmeters) for more information. The underlying GeoLocator you can choose to use 'DesiredAccuracy' or 'DesiredAccuracyInMeters'. Since this plugins default configuration accepts meters, the default desiredAccuracy is mapped to the Windows Phone DesiredAccuracyInMeters leaving the DesiredAccuracy enum empty. For more info see the [MS docs](http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.desiredaccuracyinmeters) for more information.
## Licence ## ## Licence ##
......
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