url: 'http://only.for.android.com/update_location.json', // <-- Android ONLY: your server url to send locations to
url: 'http://only.for.android.com/update_location.json', // <-- Android ONLY: your server url to send locations to
params: { // <-- Android ONLY: HTTP POST params sent to your server when persisting locations.
params: {
auth_token: 'user_secret_auth_token',
auth_token: 'user_secret_auth_token', // <-- Android ONLY: HTTP POST params sent to your server when persisting locations.
foo: 'bar'
foo: 'bar' // <-- Android ONLY: HTTP POST params sent to your server when persisting locations.
},
},
headers: { // <-- Android ONLY: Optional HTTP headers sent to your configured #url when persisting locations
headers: { // <-- Android ONLY: Optional HTTP headers sent to your configured #url when persisting locations
"X-Foo": "BAR"
"X-Foo": "BAR"
},
},
desiredAccuracy: 10,
desiredAccuracy: 10,
stationaryRadius: 20,
stationaryRadius: 20,
distanceFilter: 30,
distanceFilter: 30,
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationTitle: 'Background tracking', // <-- android only, customize the title of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
notificationText: 'ENABLED', // <-- android only, customize the text of the notification
activityType: 'AutomotiveNavigation',
activityType: 'AutomotiveNavigation',
...
@@ -99,7 +99,7 @@ NOTE: The plugin includes `org.apache.cordova.geolocation` as a dependency. You
...
@@ -99,7 +99,7 @@ NOTE: The plugin includes `org.apache.cordova.geolocation` as a dependency. You
## Behaviour
## Behaviour
The plugin has features allowing you to control the behaviour of background-tracking, striking a balance between accuracy and battery-usage. In stationary-mode, the plugin attempts to descrease its power usage and accuracy by setting up a circular stationary-region of configurable #stationaryRadius. iOS has a nice system [Significant Changes API](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringSignificantLocationChanges), which allows the os to suspend your app until a cell-tower change is detected (typically 2-3 city-block change) Android uses [LocationManager#addProximityAlert](http://developer.android.com/reference/android/location/LocationManager.html).
The plugin has features allowing you to control the behaviour of background-tracking, striking a balance between accuracy and battery-usage. In stationary-mode, the plugin attempts to descrease its power usage and accuracy by setting up a circular stationary-region of configurable #stationaryRadius. iOS has a nice system [Significant Changes API](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringSignificantLocationChanges), which allows the os to suspend your app until a cell-tower change is detected (typically 2-3 city-block change) Android uses [LocationManager#addProximityAlert](http://developer.android.com/reference/android/location/LocationManager.html). Windows Phone does not have such a API.
When the plugin detects your user has moved beyond his stationary-region, it engages the native platform's geolocation system for aggressive monitoring according to the configured `#desiredAccuracy`, `#distanceFilter` and `#locationTimeout`. The plugin attempts to intelligently scale `#distanceFilter` based upon the current reported speed. Each time `#distanceFilter` is determined to have changed by 5m/s, it recalculates it by squaring the speed rounded-to-nearest-five and adding #distanceFilter (I arbitrarily came up with that formula. Better ideas?).
When the plugin detects your user has moved beyond his stationary-region, it engages the native platform's geolocation system for aggressive monitoring according to the configured `#desiredAccuracy`, `#distanceFilter` and `#locationTimeout`. The plugin attempts to intelligently scale `#distanceFilter` based upon the current reported speed. Each time `#distanceFilter` is determined to have changed by 5m/s, it recalculates it by squaring the speed rounded-to-nearest-five and adding #distanceFilter (I arbitrarily came up with that formula. Better ideas?).
...
@@ -109,14 +109,19 @@ When the plugin detects your user has moved beyond his stationary-region, it eng
...
@@ -109,14 +109,19 @@ When the plugin detects your user has moved beyond his stationary-region, it eng
The plugin works with iOS and Android, however both platforms differ significantly in their interaction with server.
The plugin works with iOS and Android, however both platforms differ significantly in their interaction with server.
### iOS
### iOS and WP8
*Only* on iOS will the plugin execute your configured ```callbackFn```. You may manually POST the received ```GeoLocation``` to your server using standard XHR. iOS ignores the @config params ```url```, ```params``` and ```headers```.
On iOS and WP8 the plugin will execute your configured ```callbackFn```. You may manually POST the received ```GeoLocation``` to your server using standard XHR. iOS and WP8 ignore the @config params ```url```, ```params``` and ```headers```.
### Android
### Android
Android **WILL NOT** execute your configured ```callbackFn```. The plugin manages sync-ing GeoLocations to your server automatically, using the configured ```url```, ```params``` and ```headers```. Since the Android plugin must run as an autonomous Background Service, disconnected from your the main Android Activity (your foreground application), the background-geolocation plugin will continue to run, even if the foreground Activity is killed due to memory constraints. This is why the Android plugin cannot execute the Javascript ```callbackFn```, since your app is not guaranteed to keep running -- syncing locations to the server must be handled by the plugin.
Android **WILL NOT** execute your configured ```callbackFn```. The plugin manages sync-ing GeoLocations to your server automatically, using the configured ```url```, ```params``` and ```headers```. Since the Android plugin must run as an autonomous Background Service, disconnected from your the main Android Activity (your foreground application), the background-geolocation plugin will continue to run, even if the foreground Activity is killed due to memory constraints. This is why the Android plugin cannot execute the Javascript ```callbackFn```, since your app is not guaranteed to keep running -- syncing locations to the server must be handled by the plugin.
### WP8
On WP8 the plugin does not support the Stationairy location and does not implement ```getStationaryLocation()``` and ```onPaceChange()```.
Keep in mind that it is **not** possible to use ```start()``` at the ```pause``` event of Cordova/PhoneGap. WP8 suspend your app immediately and ```start()``` will not be executed. So make sure you fire ```start()``` before the app is closed/minimized.
### Config
### Config
Use the following config-parameters with the #configure method:
Use the following config-parameters with the #configure method:
...
@@ -134,7 +139,7 @@ When stopped, the minimum distance the device must move beyond the stationary lo
...
@@ -134,7 +139,7 @@ When stopped, the minimum distance the device must move beyond the stationary lo
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.
@@ -193,7 +198,7 @@ Optional HTTP headers POSTed to your server when persisting locations
...
@@ -193,7 +198,7 @@ Optional HTTP headers POSTed to your server when persisting locations
#####`@param {String} notificationText/Title`
#####`@param {String} notificationText/Title`
On Android devices it is required to have a notification in the drawer because it's a "foreground service". This gives it high priority, decreasing probability of OS killing it. To customize the title and text of the notification, set these options.
On Android devices it is required to have a notification in the drawer because it's a "foreground service". This gives it high priority, decreasing probability of OS killing it. To customize the title and text of the notification, set these options.
#####`@param {Integer} locationTimeout
#####`@param {Integer} locationTimeout
The minimum time interval between location updates, in seconds. See [Android docs](http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent)) for more information.
The minimum time interval between location updates, in seconds. See [Android docs](http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent)) for more information.
...
@@ -204,6 +209,12 @@ The minimum time interval between location updates, in seconds. See [Android do
...
@@ -204,6 +209,12 @@ The minimum time interval between location updates, in seconds. See [Android do
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
#####`{String} desiredAccuracy`
In 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.
/// Geolocator and RunningInBackground are required properties to run in background
/// For more information read http://msdn.microsoft.com/library/windows/apps/jj662935(v=vs.105).aspx
/// </summary>
publicstaticGeolocatorGeolocator{get;set;}
publicstaticboolRunningInBackground{get;set;}
/// <summary>
/// When start() is fired immediate after configure() in javascript, configure may not be finished yet, IsConfigured and IsConfiguring are used to keep track of this
// In our case this property has always a value, if left empty or below zero the default will be 100 meter but can be overridden via parameter DesiredAccuracy