Skip to content

Data types

Every type below is a named export re-exported from the package root, so you can import them directly for your own function signatures and component props:

import type { Location, State, Geofence } from '@dc-bgeo/react-native-background-geolocation';

Only the fields the app (and its backend) actually rely on are typed strictly here. A few object-shaped config and options types carry a permissive [key: string]: any index signature — unknown keys pass through uninterpreted rather than causing a type error.

Location & sensors

Location

The core location record. It’s the payload of onLocation and (when a fix exists) onMotionChange and onHeartbeat; the resolved value of getCurrentPosition(), watchPosition(), setOdometer()/resetOdometer(), and sync()/getLocations(); and the accepted shape for insertLocation() (as a Partial<Location>).

FieldTypeDescription
uuidstringUnique record id.
timestampstringISO-8601 UTC.
agenumberOptional. Fix age in milliseconds at the time it was processed.
odometernumberCumulative odometer reading, metres.
coordsCoordsPosition/motion fields.
activityMotionActivityClassified motion activity at the time of the fix.
batteryBatteryDevice battery snapshot.
is_movingboolean | nullMotion-state machine’s verdict at the time of this fix. null while a cold-started session’s first fixes are still in the unconfirmed-MOVING probing window — up to stopTimeout minutes after start(). The engine emits null there by design, so a server falls back to coords.speed instead of trusting a phantom “started moving”. Treat null the same as false.
samplebooleanOptional. true when this Location was resolved by getCurrentPosition() — either an existing fix served for a fresh-enough maximumAge, or the best (most accurate) of several fixes sampled internally — rather than delivered by the ambient tracking stream. The intermediate fixes collected while sampling for the best one are never themselves surfaced as separate Location records. Also true on the fix resolved by setOdometer()/resetOdometer() — that fix carries event: 'odometer' (see the event field below) rather than coming from getCurrentPosition().
eventstringOptional. Tags why this record was produced when it isn’t a plain tracked fix. Observed values: 'motionchange' (the record captured just before entering the stationary state) and 'odometer' (the fix resolved by setOdometer()/resetOdometer()).
extrasobjectOptional passthrough — e.g. { watch: true } on watchPosition() fixes, { heartBeat: true }, { getCurrentPosition: true }. Config-level extras form the base of every record; per-call extras are layered on top.

Snake_case: is_moving mirrors the wire format the native engines emit (camelCase elsewhere in this type, but this one field is snake_case — see also Coords and Battery below, which are almost entirely snake_case).

Coords

Nested inside Location.coords.

FieldTypeDescription
latitudenumberDegrees.
longitudenumberDegrees.
accuracynumberHorizontal accuracy, metres.
altitudenumberOptional. Metres above sea level.
altitude_accuracynumberOptional. Vertical accuracy, metres.
speednumberOptional. Metres/second.
speed_accuracynumberOptional. Metres/second.
headingnumberOptional. Degrees.
heading_accuracynumberOptional. Degrees.
ellipsoidal_altitudenumberOptional. Metres, WGS84 ellipsoidal (as opposed to altitude, which is mean-sea-level/geoid-based).

Snake_case: altitude_accuracy, speed_accuracy, heading_accuracy, and ellipsoidal_altitude are snake_case — they mirror the wire format the native engines emit, unlike latitude/longitude/accuracy/altitude/speed/heading.

MotionActivity

Nested inside Location.activity. Its type values are also the vocabulary accepted by config.triggerActivities (a CSV of these same strings).

FieldTypeDescription
type'still' | 'on_foot' | 'walking' | 'running' | 'on_bicycle' | 'in_vehicle' | 'unknown'Classified activity.
confidencenumberClassifier confidence for type.

Snake_case: the field names (type, confidence) are plain camelCase, but three of the type enum values themselves — on_foot, on_bicycle, in_vehicle — are snake_case, again mirroring the native wire format.

Battery

Nested inside Location.battery.

FieldTypeDescription
levelnumberBattery level, 0.0–1.0.
is_chargingbooleanWhether the device is currently charging.

Snake_case: is_charging mirrors the native wire format.

HeadingEvent

One smoothed compass sample — the payload of watchHeading()’s success callback.

FieldTypeDescription
headingnumberSmoothed heading in degrees, 0–360 (0 = north, clockwise).
accuracynumberPlatform-native passthrough, deliberately not harmonized. iOS: CLHeading.headingAccuracy, the maximum deviation in degrees (negative means invalid). Android: the magnetometer calibration level, an int 0–3 (0 unreliable .. 3 high).
isTruebooleantrue when heading is true north (declination applied from the last known fix on Android / CLHeading.trueHeading on iOS); false — magnetic — before a fix exists or while uncalibrated.

State

The tracker’s state snapshot: resolved by ready(), setConfig(), start(), stop(), and getState(). Every field past enabled is optional — State documents the superset of health/diagnostic fields either native engine may populate, not a fixed cross-platform guarantee, and the type’s own index signature ([key: string]: any) admits further engine-specific fields not listed here.

FieldTypeDescription
enabledbooleanWhether tracking is enabled (the persisted on/off intent).
trackingActivebooleanOptional. Whether the tracking engine currently has an active location request outstanding.
authorizationnumberOptional. One of the AUTHORIZATION_STATUS_* constants.
lastRawFixAgenumber | nullOptional, nullable. Diagnostic: age of the last raw fix (before filtering), in seconds. null until one arrives.
lastAcceptedFixAgenumber | nullOptional, nullable. Diagnostic: age of the last accepted fix (after filtering), in seconds. null until one arrives.
lastLocationErrorstring | nullOptional, nullable. Diagnostic: the most recent location error message.
locationFailureCountnumberOptional. Diagnostic counter.
backgroundRearmCountnumberOptional. Diagnostic counter.
watchdogRecoveryCountnumberOptional. Diagnostic counter.
wakeRearmCountnumberOptional. Diagnostic counter.
stationaryRegionArmedbooleanOptional. Diagnostic.
monitoredWakeRegionsnumberOptional. Diagnostic counter.
lastWakeErrorstring | nullOptional, nullable. Diagnostic: the most recent wake-region error message.
trackingModenumberOptional. Diagnostic.
isMovingbooleanOptional. Current motion-state-machine verdict — same value as onMotionChange’s isMoving.
schedulerEnabledbooleanOptional. Diagnostic.
odometernumberOptional. Cumulative odometer reading, metres.
geofenceCountnumberOptional. Diagnostic counter.
lastGeofenceErrorstring | nullOptional, nullable. Diagnostic: the most recent geofence-registration error message.
connectedbooleanOptional. Validated-internet connectivity — see ConnectivityChangeEvent.

Events

ProviderChangeEvent

Payload of onProviderChange and the resolved value of getProviderState() (same shape).

FieldTypeDescription
statusnumberOne of the AUTHORIZATION_STATUS_* constants — 3 is Always.
enabledbooleanWhether location services are on at all.
gpsbooleanGPS provider enabled.
networkbooleanNetwork provider enabled.
accuracyAuthorizationnumberOptional, iOS only — ACCURACY_AUTHORIZATION_FULL/REDUCED.
insufficientlyInUsebooleanOptional, iOS 18+ only. true while authorization is granted but iOS refuses background runtime because the app hasn’t been opened since it was relaunched in the background — tracking degrades to short wake bursts. Prompt the user to open the app to restore continuous tracking.

MotionChangeEvent

Payload of onMotionChange.

FieldTypeDescription
isMovingbooleantrue on the moving transition, false on the stationary transition.
locationLocationOptional (location?: Location | null) — absent (Android) or null (iOS) on the very first motionchange of a tracking session, before any fix exists yet (the initial probe fires from start() ahead of any location). Guard before dereferencing — see the Events reference for the same caveat.

GeofenceEvent

Payload of onGeofence.

FieldTypeDescription
identifierstringThe geofence’s identifier.
action'ENTER' | 'EXIT' | 'DWELL'The transition type.
locationLocationThe fix that triggered the transition.
extrasobjectOptional. The geofence’s own extras, echoed back.

GeofencesChangeEvent

Payload of onGeofencesChange — a delta of the OS-registered subset, not the full persisted set (see Geofence below and the Geofencing guide).

FieldTypeDescription
onGeofence[]Geofences newly registered with the OS.
offGeofence[]Geofences just unregistered.

HttpEvent

Payload of onHttp — fired once per completed location-sync HTTP request (log uploads do not emit this event; see the logging guide).

FieldTypeDescription
successbooleantrue when status is 2xx.
statusnumberHTTP status code; 0 when the request never got a response (network error).
responseTextstringResponse body (or the error message when status is 0), truncated to 1024 characters.

ConnectivityChangeEvent

Payload of onConnectivityChange. Fired on validated-internet transitions (Android NET_CAPABILITY_VALIDATED / iOS NWPath.satisfied — a captive-portal Wi-Fi network reports false); a newly-registered listener also immediately receives the current state as a synthetic first delivery.

FieldTypeDescription
connectedbooleanValidated-internet reachability.

CrashEvent

Payload of onCrash — an on-device collision confirmation. Armed only while moving, off by default; see config.crashDetection.

FieldTypeDescription
timestampstringISO-8601 UTC, the confirmation moment.
peakGnumberPeak impact magnitude, in g.
impactDurationMsnumberDuration of the impact signature, in ms.
preImpactSpeedMpsnumberSpeed immediately before impact, in m/s.
locationLocationOptional — the last known fix at confirmation time, or null if none was available.

DistractionEvent

Payload of onDistraction — an on-device distracted-driving episode. Armed only while moving, off by default; see config.distractionDetection. This detects the phone being physically handled at driving speed — see Limitations for what it cannot see.

FieldTypeDescription
timestampstringISO-8601, the moment the episode closed.
startTimestampstringISO-8601, the episode start (same instant as the dds extras key below).
durationSecnumberFinal episode duration in seconds (same value as the ddd extras key below).
cause'h' | 's' | 'c''h' handling-only (iOS), 's' handling + active screen (Android), 'c' reserved for calls (not implemented).
locationLocationOptional — the last known fix at close time, or null if none was available.

Distraction extras keys

While an episode is open (and never lost to a sparse fix stream), the engine stamps these keys into the extras of every uploaded Location — this is the wire contract a backend parses, independent of the distraction event above:

KeyTypeWhen presentMeaning
ddsnumberOn every uploaded fix while an episode is open, and on the closing fix.Unix seconds of the episode start. This value doubles as the episode id.
ddcstringAlongside dds.Cause: 'h' handling-only (iOS), 's' handling + active screen (Android), 'c' reserved for calls (not implemented).
dddnumberOnly on the first fix persisted after the episode ends.Final episode duration in seconds.

Rules for a backend consuming these keys:

  • Group fixes into an episode by equal dds value, not by adjacency in the fix stream — grouping by equal value survives gaps in delivery.
  • Episode duration is ddd from the closing fix. If the closing fix never arrives, fall back to the span of fixes carrying that dds — this is only a lower bound.
  • A short episode can produce no fixes “inside” it. If an episode is shorter than the interval between fixes, the next persisted fix simply carries dds, ddc and ddd together. Episodes are therefore never lost to a sparse fix stream.
  • A pending close wins a race with a new open. If a new episode opens before the previous episode’s close has been flushed to a fix, that fix carries the pending close’s dds/ddc/ddd triple in full; the newly opened episode’s dds/ddc pair is deferred to the next record. Grouping by equal dds (above) is unaffected either way.
  • Do not count episodes off the location stream. The closing triple (dds/ddc/ddd) rides every record built between the close and the first record that is actually persisted, so a sample: true one-shot and the location embedded inside another event can each carry it more than once. The uploaded-record contract is unaffected, but a consumer must count episodes from the distraction event instead — it fires once per episode in normal operation, but a rare disarm race can publish a second distraction event for the same episode (same dds/startTimestamp, different durationSec/ddd). A consumer that needs exact counts should dedupe by startTimestamp (equivalently dds).

Geofencing

Geofence

A persisted geofence definition — the shape accepted by addGeofence()/addGeofences() and returned by getGeofences() and the on/off arrays of GeofencesChangeEvent. See the Geofencing guide for validation rules, proximity slicing, and DWELL semantics.

FieldTypeDescription
identifierstringUnique geofence id.
radiusnumberMetres.
latitudenumberDegrees.
longitudenumberDegrees.
notifyOnEntrybooleanOptional.
notifyOnExitbooleanOptional.
notifyOnDwellbooleanOptional.
loiteringDelaynumberOptional. Milliseconds; required alongside notifyOnDwell for a DWELL transition.
extrasobjectOptional. Echoed back on the corresponding GeofenceEvent.

Positioning options

CurrentPositionOptions

Parameter of getCurrentPosition().

FieldTypeDescription
persistbooleanOptional. Whether the resolved fix is added to the upload queue like a normal tracked point.
samplesnumberOptional. Number of fixes to sample before returning the best (most accurate) one.
timeoutnumberOptional. Seconds to wait before giving up. Default 30.
maximumAgenumberOptional. Accept a cached fix up to this many milliseconds old instead of sampling a new one.
desiredAccuracynumberOptional. One of the DESIRED_ACCURACY_* constants.
extrasobjectOptional. Merged into the returned location’s extras.

WatchPositionOptions

Parameter of watchPosition().

FieldTypeDescription
intervalnumberOptional. Desired update interval, milliseconds.
desiredAccuracynumberOptional. One of the DESIRED_ACCURACY_* constants.
persistbooleanOptional. Whether fixes are added to the upload queue.
extrasobjectOptional. Merged into each returned location’s extras.

HeadingOptions

Parameter of watchHeading(). All fields optional; an omitted field lets the engine’s own default apply.

FieldTypeDescription
minIntervalMsnumberOptional. Minimum gap between emitted samples, ms. Default 40 (caps output at 25 Hz).
minDeltaDegnumberOptional. Minimum heading change to emit, degrees, along the shortest arc. Default 0.5.
smoothingTauMsnumberOptional. Time constant of the exponential smoother on the unit circle, ms — larger is steadier and laggier. Default 120.

The first sample after watchHeading() starts — or restarts after a foreground resume — is always emitted, regardless of minIntervalMs/minDeltaDeg.

Logging

LogEntry

Resolved array-element type of getLog(); written by logger.error/warn/info/debug/verbose and the native engine itself. See the logging guide for retention and upload cadence.

FieldTypeDescription
tsstringISO-8601 UTC.
levelnumber1=ERROR, 2=WARN, 3=INFO, 4=DEBUG, 5=VERBOSE.
src'native' | 'js'Whether the line originated in the native engine or app-side JS (logger.* calls).
eventstringShort event tag.
messagestringOptional. Human-readable log line.
dataanyOptional. JSON-serialized data attached to the line.

Headless

HeadlessEvent

Parameter of the task passed to registerHeadlessTask() Android . Unlike every other event type on this page, there is no params/payload wrapper — the event’s payload fields are flattened alongside name directly on the same object (enforced by the type’s [key: string]: any index signature). iOS never invokes a registered headless task at all, since there’s no AppRegistry-driven headless service on that platform — see registerHeadlessTask() and the boot & killed-app guide.

FieldTypeDescription
name'heartbeat' | 'motionchange' | 'geofence' | 'providerchange' | 'powersavechange' | 'http' | 'connectivitychange'The event type. The union matches the Android engine’s headless dispatch set exactly; 'location' is deliberately not part of it — see below.
[key: string]anyThe rest of the event’s fields, flattened alongside name — e.g. a headless motionchange carries isMoving/location directly on this object, not nested under a params key.

No headless location: the Android engine never dispatches a location event headlessly, and the union reflects that — the runtime set of headless-dispatched event names is exactly heartbeat, motionchange, geofence, providerchange, powersavechange, http, and connectivitychange, so narrowing on event.name is exhaustive. High-frequency location fixes are deliberately excluded to avoid spinning up Android’s HeadlessJsTaskService (and a wakelock) per fix while tracking, which would drain battery and risk ANRs/foreground-service-start restrictions; fixes taken while the JS context isn’t running are still durably queued and uploaded natively. This mirrors the same note under onLocation on the Events reference.

Subscriptions

Subscription

Returned by every on* listener method on the Events reference.

FieldTypeDescription
remove() => voidDetaches this one listener. To tear down every listener at once, call removeListeners() instead.