[iOS only]
Presumably, this affects iOS stop-detect algorithm. Apple is vague about what exactly this option does.
Available values are defined as constants upon the BackgroundGeolocation class.
[Android only]
Allow recording locations which are duplicates of the previous.
Configures the SDK for Authorization with your server (eg: JSON Web Token).
The SDK will automatically apply the supplied token to HTTP request's Authorization header, eg:
"Authorization": "Bearer abcd1234..."
If provided with Authorization.refreshUrl and Authorization.expires, the SDK can automatically re-register for a new token after expiration.
Immediately upload each recorded location to your configured url.
The minimum number of persisted records the plugin must accumulate before triggering an autoSync action.
(Android 11+) Configure the dialog presented to the user when Always location permission is requested.
Just as in iOS 13/14, Android 11 has changed location authorization and no longer offers the [Allow all the time]
button on the location authorization dialog. Instead, Android now offers a hook to present a custom dialog to the user where you will explain exactly why you require "Allow all the time" location permission.
This dialog can forward the user directly to your application's Location Permissions screen, where the user must explicity authorize [Allow all the time]
. The Background Geolocation SDK will present this dialog, which can be customized with backgroundPermissionRationale.
positiveAction
on the dialog, it will not be shown again (pressing [Cancel]
button does not count).[Ask every time]
, the backgroundPermissionRationale can be shown once again.
POST multiple locations to your url in a single HTTP request.
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 database to your server in a single HTTP POST request. With batchSync false
, an HTTP POST
request will be initiated for each location in database.
batchSync: true
— All accumulated locations POSTed in 1 HTTP request.Configure the plugin to emit sound effects and local-notifications during development.
[Android only]
Sets the maximum wait time in milliseconds for location updates.
Defaults to 0
(no defer). If you pass a value at least 2x larger than the interval specified with locationUpdateInterval, then location delivery may be delayed and multiple locations can be delivered at once. Locations are determined at the locationUpdateInterval rate, but can be delivered in batch after the interval you set in this method. This can consume less battery and give more accurate locations, depending on the device's hardware capabilities. You should set this value to be as large as possible for your needs if you don't need immediate location delivery.
Specify the desired-accuracy of the geolocation system.
The following constants are defined upon the BackgroundGeolocation class:
Name | Location Providers | Description |
---|---|---|
BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION | (iOS only) GPS + Wifi + Cellular | Highest power; highest accuracy |
BackgroundGeolocation.DESIRED_ACCURACY_HIGH | GPS + Wifi + Cellular | Highest power; highest accuracy |
BackgroundGeolocation.DESIRED_ACCURACY_MEDIUM | Wifi + Cellular | Medium power; Medium accuracy; |
BackgroundGeolocation.DESIRED_ACCURACY_LOW | Wifi (low power) + Cellular | Lower power; No GPS |
BackgroundGeolocation.DESIRED_ACCURACY_VERY_LOW | Cellular only | Lowest power; lowest accuracy |
BackgroundGeolocation.DESIRED_ACCURACY_LOWEST | (iOS only) | Lowest power; lowest accuracy |
DESIRED_ACCURACY_HIGH
uses GPS. speed
, heading
and altitude
are available only from GPS.The maximum location accuracy allowed for a location to be used for Location.odometer calculations.
Defaults to 100
. If a location arrives having accuracy > desiredOdometerAccuracy
, that location will not be used to update the
odometer. If you only want to calculate odometer from GPS locations, you could set desiredOdometerAccuracy: 10
.
This will prevent odometer updates when a device is moving around indoors, in a shopping mall, for example.
Indicates if the app was launched after the device was rebooted.
true
when the iOS app was launched in the background. Always false
for Android.
iOS apps can be launched in the background due to a background-fetch event, geofence events or exiting the Config.stationaryRadius.
One might use this flag to choose to load only minimal resources until the iOS app is determined to have launched into the foreground.
Disable autoSync HTTP requests when device is connected to a Cellular connection.
Defaults to false
. Set true
to allow autoSync only when device is connected to Wifi.
WARNING This option is ignored when manually invoking BackgroundGeolocation.sync.
Defaults to false
. Set true
to disable automatic, speed-based distanceFilter auto-scaling. By default, the SDK automatically
increases distanceFilter as speed increases (and decreases it as speed decreases) in order to record fewer locations and conserve energy.
Disables automatic authorization alert when plugin detects the user has disabled location authorization.
Disable the plugin requesting "Motion & Fitness" (ios) or "Physical Activity" (android >= 10) authorization from the User.
[Android-only]
Disables the automatic insert of a location record into the SDK's SQLite database and subsequent HTTP upload if configured with Config.url.
When a onProviderChange event fires, the Android SDK has traditionally recorded a location to show exactly when and where the state of location-services was changed (eg: Location-services disabled).
Android has done this automatically due to the difficulty with some platforms' implementation of Headless Tasks (enableHeadless), where Cordova and Capacitor require implementations using Java code, which is often difficult for most developers.
Some developers' servers have strict HTTP JSON payloads and possibly using locationTemplate, where it's impossible to template the automatically appended provider
key in the payload.
Set true
to disable this default behaviour.
Disable motion-activity related stop-detection.
The minimum distance (measured in meters) a device must move horizontally before an update event is generated.
However, by default, distanceFilter
is elastically auto-calculated by the plugin: When speed increases, distanceFilter
increases; when speed decreases, so too does distanceFilter
.
Controls the scale of automatic speed-based distanceFilter elasticity.
Increasing elasticityMultiplier
will result in fewer location samples as speed increases. A value of 0
has the same effect as
disableElasticity true
.
[Android only]
Enables "Headless" operation allowing you to respond to events after you app has been terminated with stopOnTerminate false
.
Enable extra timestamp meta data to be appended to each recorded location, including system-time.
true
when the SDK has been enabled via methods start or startGeofences. When false
, the
SDK is completely OFF. No tracking of any kind will occur. The SDK will consume no energy.
Optional arbitrary key/values {}
applied to each recorded location.
📘 See HTTP Guide
[Android only]
Explicitly set the fastest interval for location updates, in milliseconds.
[Android only]
Configure the plugin service to run as a more robust "Foreground Service".
When a device is already within a just-created geofence, fire the enter transition immediately.
Defaults to true
. Set false
to disable triggering a geofence immediately if device is already inside it.
[Android only]
Enable high-accuracy for geofence-only mode (See BackgroundGeolocation.startGeofences).
Defaults to false
. Runs Android's BackgroundGeolocation.startGeofences with a foreground service (along with its corresponding persistent Notification.
Configuring geofenceModeHighAccuracy: true
will make Android geofence triggering far more responsive. In this mode, the usual config options to control location-services will be applied:
With the default geofenceModeHighAccuracy: false
, a device will have to move farther into a geofence before the ENTER event fires and farther out of a geofence before
the EXIT event fires.
The more aggressive you configure the location-update params above (at the cost of power consumption), the more responsive will be your geofence-triggering.
The radius around current location to query for geofences to activate monitoring upon.
The default and minimum is 1000
meters. See related event BackgroundGeolocation.onGeofencesChange. When using Geofences, the
plugin activates only those in proximity (the maximum geofences allowed to be simultaneously monitored is limited by the platform,
where iOS allows only 20 and Android. However, the plugin allows you to create as many geofences as you wish (thousands even).
It stores these in its database and uses spatial queries to determine which 20 or 100 geofences to activate.
Optional custom template for rendering GeofenceEvent JSON request data in HTTP requests.
Optional HTTP headers applied to each HTTP request.
Controls the rate (in seconds) the BackgroundGeolocation.onHeartbeat event will fire.
The root property of the JSON schema where location-data will be attached.
HTTP request timeout in milliseconds.
HTTP request timeouts will fire the BackgroundGeolocation.onHttp. Defaults to 60000 ms
.
Configure the initial tracking-state after BackgroundGeolocation.start is called.
The plugin will immediately enter the tracking-state, by-passing the stationary state. If the device is not currently moving, the stop-detection system will still engage. After stopTimeout minutes without movement, the plugin will enter the stationary state, as usual.
[iOS only]
Controls the text-elements of the plugin's location-authorization dialog.
Defines the desired location-authorization request you wish for the user to authorize:
Always
WhenInUse
Any
Optional custom template for rendering Location JSON request data in HTTP requests.
The default timeout in seconds when requesting a location before the SDK gives up and fires a LocationError.
Defaults to 60
seconds.
[Android only]
Set the desired interval for active location updates, in milliseconds.
Controls the order that locations are selected from the database (and uploaded to your server).
Defaults to ascending (ASC
), where oldest locations are synced first. Descending (DESC
) uploads latest locations first.
Controls the volume of recorded events in the plugin's logging database.
BackgroundGeolocation contains powerful logging features. By default, the plugin boots with a value of BackgroundGeolocation.LOG_LEVEL_OFF,
storing logMaxDays (default 3
) days worth of logs in its SQLite database.
The following log-levels are defined as constants on this BackgroundGeolocation class:
Maximum number of days to persist a log-entry in database.
Controls the number of records attached to each batch HTTP request.
Maximum number of days to store a geolocation in plugin's SQLite database.
Maximum number of records to persist in plugin's SQLite database.
Default -1
means no limit.
The HTTP method to use when creating an HTTP request to your configured url.
Defaults to POST
. Valid values are POST
, PUT
and OPTIONS
.
[Android only]
Optionally add a delay in milliseconds to trigger Android into the moving state when Motion API reports the device is moving (eg: on_foot
, in_vehicle
)
This can help prevent false-positive motion-triggering when one moves about their home, for example. Only if the Motion API stays in the moving state for motionTriggerDelay
milliseconds will the plugin trigger into the moving state and begin tracking the location.
If the Motion API returns to the still
state before motionTriggerDelay
times-out, the trigger to the moving state will be cancelled.
[Android only] Configures the persistent foreground-service Notification required by Android.
See Notification for detailed usage.
⚠️ DEPRECATED: Notification.channelName
⚠️ DEPRECATED: Use Notification.color
⚠️ DEPRECATED: Notification.largeIcon
⚠️ DEPRECATED Notification.priority
⚠️ DEPRECATED: Use Notification.smallIcon
⚠️ DEPRECATED: Use Notification.text
⚠️ DEPRECATED: Use Notification.title
Optional HTTP params
appended to the JSON body of each HTTP request.
[iOS only]
Configure iOS location API to never automatically turn off.
Allows you to specify which events to persist to the SDK's internal database: locations | geofences | all (default).
Note that all recorded location and geofence events will always be provided to your [BackgroundGeolocation.onLocation] and [BackgroundGeolocation.onGeofence] events, just that the persistence of those events in the SDK's internal SQLite database can be limited. Any event which has not been persisted to the SDK's internal database will also not therefore be uploaded to your [url] (if configured).
Name | Description |
---|---|
BackgroundGeolocation.PERSIST_MODE_ALL | (DEFAULT) Persist both geofence and location events |
BackgroundGeolocation.PERSIST_MODE_LOCATION | Persist only location events (ignore geofence events) |
BackgroundGeolocation.PERSIST_MODE_GEOFENCE | Persist only geofence events (ignore location events) |
BackgroundGeolocation.PERSIST_MODE_NONE | Persist nothing (neither geofence nor location events) |
This option is designed for specializd use-cases and should generally not be used. For example, some might wish to
run the plugin in regular tracking mode with BackgroundGeolocation.start but only record geofence events. In this case,
one would configure persistMode: BackgroundGeolocation.PERSIST_MODE_GEOFENCE
.
[iOS only]
Prevent iOS from suspending your application in the background after location-services have been switched off.
Controls whether the plugin should first reset the configuration when #ready
is executed before applying the supplied config {}
.
Defaults to true
. The SDK can optionally re-apply its persisted configuration with each boot of your application, ignoring the config {}
supplied to the #ready
method.
Android only Force the Android scheduler to use AlarmManager
(more precise) instead of JobScheduler
. Defaults to false
.
BackgroundGeolocation.ready({
schedule: ["1-7 09:00-17:00"],
scheduleUseAlarmManager: true
});
true
when the SDK is currently configured with a schedule and startSchedule has been executed.
stopSchedule will set this to false
.
[iOS Only] A Boolean indicating whether the status bar changes its appearance when an app uses location services in the background with Always
authorization.
The default value of this property is true
. The background location usage indicator is a blue bar or a blue pill in the status bar on iOS; on watchOS the indicator is a small icon. Users can tap the indicator to return to your app.
This property affects only apps that received Always
authorization. When such an app moves to the background, the system uses this property to determine whether to change the status bar appearance to indicate that location services are in use. Set this value to true to maintain transparency with the user.
For apps with When In Use authorization, the system changes the appearance of the status bar when the app uses location services in the background.
Android-only
Experimental filter to ignore anomalous locations that suddenly jump an unusual distance from last.
The SDK will calculate an apparent speed and distance relative to last known location. If the location suddenly
teleports from last location, it will be ignored.
The measurement is in meters/second. The default is to throw away any location which apparently moved at 300 meters/second from last known location.
Controls whether to resume location-tracking after device is rebooted.
Defaults to false
. Set true
to engage background-tracking after the device reboots.
[iOS only]
The minimum distance the device must move beyond the stationary location for aggressive background-tracking to engage.
take ~200 meters of movement before the plugin begins tracking.
[iOS only]
Allows the iOS stop-detection system to be delayed from activating.
Automatically BackgroundGeolocation.stop when the stopTimeout elapses.
Controls whether to continue location-tracking after application is terminated.
Minutes to wait in moving state with no movement before considering the device stationary.
Value | Description |
---|---|
0 |
Monitoring geofences only |
1 |
Monitoring location + geofences |
Convenience option to automatically configures the SDK to upload locations to the Transistor Software demo server at http://tracker.transistorsoft.com (or your own local instance of background-geolocation-console)
See TransistorAuthorizationToken. This option will automatically configures the url to point at the Demo server as well as well as the required Authorization configuration.
Configures a comma-separated list of motion-activities which are allow to trigger location-tracking.
⚠️ Warning: Requires that the user grant your app the "Motion/Health" permission.
Your server url
where you wish the SDK to automatically upload location data.
Set true
in order to disable constant background-tracking. Locations will be recorded only periodically.
Defaults to false
. A location will be recorded only every 500
to 1000
meters (can be higher in non urban environments; depends upon the spacing of Cellular towers). Many of the plugin's configuration parameters will have no effect, such as distanceFilter, stationaryRadius, activityType, etc.
Using significantChangesOnly: true
will provide significant power-saving at the expense of fewer recorded locations.
Engages the iOS Significant Location Changes API API for only periodic location updates every 500-1000 meters.
Generated using TypeDoc
This
State
object contains all the provided Config options in addition to: