Skip to content

[Bug]: locationTemplate not applied in all cases #2658

Description

@roelvdboom

Required Reading

  • Confirmed

Plugin Version

5.4.0

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

Samsung S24 FE

Device operating-systems(s)

Android 16

React Native / Expo version

0.86.2

What happened?

On our server we're receiving messages that are not in compliance with the locationTemplate.

Plugin Code and/or Config

const LOCATION_TEMPLATE = '{"timestamp": "<%= timestamp %>", "latitude": <%= latitude %>, "longitude": <%= longitude %>, "accuracy": <%= accuracy %>, "speed": <%= speed %>}';

{
    geolocation: {
        desiredAccuracy:
        BackgroundGeolocation.DesiredAccuracy.High,

        // When any motion-type activity is detected (eg: on_foot),
        // the plugin will enter the moving state, turn location-services on and begin recording
        // a location each distanceFilter meters.
        // default: 10
        distanceFilter: user
            ? user.tenant.settings.locationService
                .distanceFilter
            : 50,

        // Activity Recognition
        // https://github.com/transistorsoft/react-native-background-geolocation/wiki/Philosophy-of-Operation#stoptimeout
        // When the MotionActivity API first reports an activity of still,
        // the plugin will engage its "stop-detection" system. This system involves initiating
        // a timer of stopTimeout minutes. When this timer finally expires,
        // the plugin will enter the stationary state. If the MotionActivity API reports
        // a moving-type activity before the timer times-out, the stopTimeout timer will
        // be cancelled and stop-detection will be cease -- the plugin will remain in the moving state.
        // default: 5
        stopTimeout: user
            ? user.tenant.settings.locationService.stopTimeout
            : 15,

        activityType:
        BackgroundGeolocation.ActivityType
            .AutomotiveNavigation,

        locationAuthorizationRequest: "Always",
        disableLocationAuthorizationAlert: true,
    },
    app: {
        enableHeadless: false, // Not needed since stopOnTerminate handles this for us.
        stopOnTerminate: false, // Allow the background-service to continue tracking when user closes the app.
        startOnBoot: false,
        backgroundPermissionRationale: {
            title: "Allow {applicationName} to access to this device's location in the background?",
            message:
                "In order to track your activity in the background, please enable {backgroundPermissionOptionLabel} location permission",
            positiveAction:
                "Change to {backgroundPermissionOptionLabel}",
            negativeAction: "Cancel",
        },
    },
    logger: {
        debug: __DEV__,
        logLevel: __DEV__
            ? BackgroundGeolocation.LogLevel.Debug
            : BackgroundGeolocation.LogLevel.Warning,
    },
    http: {
        url: postUrl,
        batchSync: false,
        autoSync: true,
        method: "POST",
        rootProperty: ".",
        headers: {
            Authorization: `token ${token}`,
        },
    },
    persistence: {
        locationTemplate: LOCATION_TEMPLATE,
    },
};


Event sent to the postUrl:
{
	"activity": {
		"activities": [
			"still"
		],
		"confidence": 100,
		"type": "still"
	},
	"age": 13.687,
	"battery": {
		"is_charging": false,
		"level": 0.51
	},
	"coords": {
		"accuracy": 15.53,
		"altitude": 49.9,
		"altitude_accuracy": 0.67,
		"ellipsoidal_altitude": 49.9,
		"heading": -1,
		"heading_accuracy": -1,
		"latitude": 51.0000000,
		"longitude": 5.0000000,
		"speed": -1,
		"speed_accuracy": -1
	},
	"is_moving": true,
	"odometer": 15139777.58,
	"odometer_error": 783.58,
	"recorded_at": "2026-09-10T07:16:38.283Z",
	"timestamp": "2026-09-10T07:16:24.598Z",
	"uuid": "459f0fc8-c0f4-4ad5-989c-2d527361e3c9"
}

Relevant log output

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions