react-native-background-geolocation@5.0.0-beta.1
    Preparing search index...

    Interface Location

    A Location object represents a geographic location captured by the device's native location API.

    • CLLocationManager delivers instance of CLLocation on iOS
    • FusedLocationProviderClient deliver instance of android.location.Location on Android

    Javascript Callback Schema

    {
    "timestamp": [Date], // <-- Javascript Date instance
    "event": [String], // <-- motionchange|geofence|heartbeat
    "is_moving": [Boolean], // <-- The motion-state when location was recorded.
    "uuid": [String], // <-- Universally unique identifier
    "age": [Integer], // <-- Age of the location in milliseconds
    "coords": {
    "latitude": [Double],
    "longitude": [Double],
    "accuracy": [Double],
    "speed": [Double],
    "heading": [Double],
    "altitude": [Double]
    "ellipsoidal_altitude": [Double]
    },
    "activity": {
    "type": [still|on_foot|walking|running|in_vehicle|on_bicycle],
    "confidence": [0-100%]
    },
    "battery": {
    "level": [Double],
    "is_charging": [Boolean]
    },
    "odometer": [Double/meters]
    }

    HTTP POST Schema

    The location-data schema POSTed to your server takes the following form:

    {
    "location": {
    "coords": {
    "latitude": [Double],
    "longitude": [Double],
    "accuracy": [Double],
    "speed": [Double],
    "heading": [Double],
    "altitude": [Double],
    "ellipsoidal_altitude": [Double]
    },
    "extras": { // <-- optional meta-data
    "foo": "bar"
    },
    "activity": {
    "type": [still|on_foot|walking|running|in_vehicle|on_bicycle|unknown],
    "confidence": [0-100%]
    },
    "geofence": { // <-- Present only if a geofence was triggered at this location
    "identifier": [String],
    "action": [String ENTER|EXIT]
    },
    "battery": {
    "level": [Double],
    "is_charging": [Boolean]
    },
    "timestamp": [ISO-8601 UTC], // eg: "2015-05-05T04:31:54.123Z"
    "age": [Integer], // <-- Age of the location in milliseconds
    "uuid": [String], // <-- Universally unique identifier
    "event" [String], // <-- motionchange|geofence|heartbeat
    "is_moving": [Boolean], // <-- The motion-state when recorded.
    "odometer": [Double/meters]
    }
    }
    interface Location {
        timestamp: string;
        age: number;
        odometer: number;
        odometer_error: number;
        is_moving: boolean;
        uuid: string;
        event?: string;
        mock?: boolean;
        sample?: boolean;
        coords: Coords;
        battery: Battery;
        extras?: Record<string, any>;
        geofence?: GeofenceEvent;
        activity: MotionActivity;
        provider?: ProviderChangeEvent;
    }
    Index

    Properties

    timestamp: string

    ISO-8601 UTC timestamp provided by the native location API.

    age: number

    The age of the location in milliseconds, relative to the Device system-time when the location was received. For example, if the reported age is 10000, that location was recorded 10s ago, relative to the system-time. location.timestamp + location.age = Device system-time when location was recorded.

    odometer: number

    Total distance traveled, in meters, since the odometer was last set or reset.

    The SDK continuously integrates distance between recorded locations to maintain a running total. This value increases regardless of tracking mode and persists across app restarts (unless explicitly reset).

    ℹ️ How it's calculated:

    When the odometer increases:

    • After the device moves and a new location is recorded.
    • During both moving and stationary states (if minor motion is detected).
    • In geofences-only mode, the odometer increases whenever a location is recorded for a geofence transition or stationary exit.

    When it does not increase:

    • When a sample fails accuracy thresholds.
    • When is_moving is false and no sufficient movement occurs.

    Resetting or setting the odometer:

    Persistence:

    • The odometer value is stored in State and is restored after app restart.
    • Only a user-initiated reset or explicit call to setOdometer clears it.

    Best practices:

    • Display the odometer directly to users (e.g., trip distance, workout distance).
    • Use Location.odometer_error to measure confidence in the odometer.
    • For fitness apps, consider resetting it at the beginning of each workout session.
    BackgroundGeolocation.onLocation(location => {
    console.log("Distance traveled:", location.odometer);

    if (location.odometer_error > 25) {
    console.warn("Odometer accuracy degraded");
    }
    });

    // Reset at start of a trip
    await BackgroundGeolocation.resetOdometer();

    ℹ️

    odometer_error: number

    Accumulated odometer drift, in meters.

    ℹ️ Why does this exist?

    • The SDK maintains a continuously increasing odometer value by integrating distance between recorded locations.
    • When GNSS accuracy is degraded (tunnels, downtown canyons, indoor / underground environments), distance calculations can accumulate drift.
    • The odometer_error value tells you how much uncertainty has accumulated in the current odometer estimate.

    How to use it:

    • Treat this as a “confidence interval” for odometer.
      For example, if odometer = 12000 and odometer_error = 40, the true travelled distance is likely within ±40 meters of the reported value.
    • Resetting or setting a new odometer value automatically resets odometer_error to 0.
    • Values typically remain low (e.g., < 10m) during good GPS conditions, but can grow during:
      • long tunnels
      • heavy multipath environments
      • extended indoor tracking

    Best practice:

    • Display odometer normally to end-users.
    • Use odometer_error internally for data-quality scoring, filtering, or highlighting low-accuracy segments.
    BackgroundGeolocation.onLocation(location => {
    console.log("Odometer:", location.odometer);
    console.log("Odometer drift:", location.odometer_error);

    if (location.odometer_error > 50) {
    console.warn("High odometer drift — signal quality degraded");
    }
    });

    ℹ️

    is_moving: boolean

    true if location was recorded while plugin is in the moving state.

    uuid: string

    Universally Unique Identifier. You can use this to match locations recorded at your server with those in the logs. It can also be used to ensure if the plugin has ever posted the same location twice.

    event?: string

    Event responsible for generating this location (motionchange, providerchange, geofence, heartbeat).

    mock?: boolean

    Present (and true) if the location was generated by a "Fake Location" application or simulator.

    sample?: boolean

    true if the plugin is currently waiting for the best possible location to arrive. Samples are recorded when the plugin is transitioning between motion-states (moving vs stationary) or [[BackgroundGeolocation.getCurrentPosition]]. If you're manually posting location to your server, you should not persist these "samples".

    coords: Coords

    latitude, longitude, speed, heading, etc.

    battery: Battery

    Device battery level when the location was recorded.

    extras?: Record<string, any>

    Optional arbitrary meta-data attached to this location.

    geofence?: GeofenceEvent

    If this location was recorded due to a geofence transition, the corresponding geofence-event.

    activity: MotionActivity

    Device motion-activity when this location was recorded (eg: still, on_foot, in_vehicle).

    If this location was recorded due to ProviderChangeEvent, this is a reference to the location-provider state.