State¶
Read-only snapshot of the SDK's current runtime state.
const state = await BackgroundGeolocation.getState();
console.log("[state] enabled:", state.enabled, "trackingMode:", state.trackingMode);
Properties¶
| Property | Type | Description |
|---|---|---|
| enabled | Boolean | Whether the SDK is currently tracking. |
| isMoving | Boolean | Whether the device is currently in motion. |
| trackingMode | TrackingMode | Current tracking mode: LOCATION or GEOFENCE. |
| odometer | Double | Distance travelled in metres since last reset. |
| schedulerEnabled | Boolean | Whether the scheduler is currently active. |
| didDeviceReboot | Boolean | Whether the device rebooted since the SDK was last running. |
Members¶
activity¶
activity?:ActivityConfig;
Motion recognition, stop-detection triggers, and motion-trigger delay. See ActivityConfig.
app¶
app?:AppConfig;
App lifecycle — background operation, boot behaviour, headless mode, and foreground notification. See AppConfig.
authorization¶
authorization?:AuthorizationConfig;
JWT and SAS token management with automatic refresh. See AuthorizationConfig.
didDeviceReboot¶
true when the app was launched after a device reboot.
didLaunchInBackground¶
iOS only true when the app was relaunched in the background by the OS — for
example, due to a background fetch, geofence exit, or stationary geofence
transition. On Android, background launch is handled by the Headless Task mechanism —
this property does not apply.
enabled¶
true when the SDK is actively tracking — i.e. BackgroundGeolocation.start
or BackgroundGeolocation.startGeofences has been called and not yet stopped.
geolocation¶
geolocation?:GeoConfig;
Accuracy, sampling, elasticity, stop-detection, permissions, and geofencing. See GeoConfig.
http¶
http?:HttpConfig;
Upload URL, HTTP method, sync cadence, batching, headers, and params. See HttpConfig.
isFirstBoot¶
true on the very first launch after the app is installed.
isMoving¶
true when the SDK is in the moving state (location services active);
false when stationary.
// Toggle the SDK's motion state from stationary to moving.
BackgroundGeolocation.onMotionChange((event) => {
console.log('[onMotionChange] isMoving?', event.isMoving);
});
await BackgroundGeolocation.changePace(true);
// State.isMoving is now true.
logger¶
logger?:LoggerConfig;
Debug logging, log level, and log retention. See LoggerConfig.
odometer¶
Accumulated distance traveled since the last odometer reset, in meters.
See also
- odometerError
- BackgroundGeolocation.setOdometer
- BackgroundGeolocation.getOdometer
odometerError¶
Accumulated positional error in the odometer measurement, in meters.
Reflects noise introduced by low-accuracy location samples. Use LocationFilter.odometerAccuracyThreshold to filter out low-accuracy samples from odometer calculations.
persistence¶
persistence?:PersistenceConfig;
SQLite storage, TTL, record limits, and custom extras. See PersistenceConfig.
schedulerEnabled¶
true when a AppConfig.schedule is configured and
BackgroundGeolocation.startSchedule has been called.
BackgroundGeolocation.stopSchedule sets this to false.
trackingMode¶
trackingMode:TrackingMode;
Current tracking mode.
| Value | Mode | Description |
|---|---|---|
0 |
Geofences | Geofence monitoring only — no active location tracking. |
1 |
Location | Location tracking and geofence monitoring. |
await BackgroundGeolocation.start();
let state = await BackgroundGeolocation.getState();
console.log('Tracking mode:', state.trackingMode);
// > 'Tracking mode: 1'
await BackgroundGeolocation.startGeofences();
state = await BackgroundGeolocation.getState();
console.log('Tracking mode:', state.trackingMode);
// > 'Tracking mode: 0'