Skip to content

[Bug]: geolocationTemplate not being applied #2552

@UnderTheMoonspell

Description

@UnderTheMoonspell

Required Reading

  • Confirmed

Plugin Version

5.1.0

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

Emulator

Device operating-systems(s)

iOS 26.2

React Native / Expo version

0.82.1

What happened?

We updated the lib to v5. We migrated everything with the help of Claude Opus-High. All the existing tests pass, the geofences keep being triggered as before.

Our endpoint set in the http.url property started failing and it seems the culprit is that the geolocationTemplate is not being applied.

This is the call made by the SDK to our custom endpoint after vs before the upgrade

Image Image

These are the logs of the onGeofenceEvent (taken from the function in the logs section):

Image

Plugin Code and/or Config

const geofenceTemplate =
  '{ "timestamp": "<%= timestamp %>", "uuid": "<%= uuid %>", "age": <%= age %>, "event": "<%= event %>", "odometer": <%= odometer %>, "geofence": { "identifier": "<%= geofence.identifier %>", "action": "<%= geofence.action %>" }, "coords":{ "latitude": <%= latitude %>, "longitude": <%= longitude %>, "accuracy": <%= accuracy %>, "altitude": <%= altitude %>, "altitude_accuracy": <%= altitude_accuracy %> }, "activity": { "type": "<%= activity.type %>", "confidence": <%= activity.confidence %> }, "is_mock": <%= mock %>, "is_moving": <%= is_moving %> }';

export const BACKGROUND_GEOLOCATION_DEFAULTS: BackgroundGeolocationFlagConfig = {
  geolocation: {
    desiredAccuracy: BackgroundGeolocation.DesiredAccuracy.High,
    geofenceModeHighAccuracy: true,
    geofenceInitialTriggerEntry: true,
    locationUpdateInterval: 1000,
    distanceFilter: 10,
    disableLocationAuthorizationAlert: true,
    locationAuthorizationRequest: 'Always',
    allowIdenticalLocations: false,
    enableTimestampMeta: false,
    filter: {
      policy: BackgroundGeolocation.LocationFilterPolicy.Conservative,
      useKalman: true,
      kalmanProfile: BackgroundGeolocation.KalmanProfile.Conservative,
      trackingAccuracyThreshold: 100,
      odometerAccuracyThreshold: 20,
    },
  },
  app: {
    stopOnTerminate: false,
    startOnBoot: true,
  },
  persistence: {
    disableProviderChangeRecord: true,
    persistMode: BackgroundGeolocation.PersistMode.Geofence,
    maxDaysToPersist: 3,
    geofenceTemplate,
  },
  logger: {
    debug: !!__DEV__,
    logLevel: __DEV__ ? BackgroundGeolocation.LogLevel.Verbose : BackgroundGeolocation.LogLevel.Off,
    logMaxDays: __DEV__ ? 7 : 3,
  },
  activity: {
    disableMotionActivityUpdates: false,
  },
};



  const initBackgroundGeolocation = useCallback(
    async (device: DeviceInfo) => {
      try {
        const state = await BackgroundGeolocation.ready({
          reset: false,
          ...(BACKGROUND_GEOLOCATION_DEFAULTS as Partial<GeoConfig>),
          app: {
            ...BACKGROUND_GEOLOCATION_DEFAULTS.app,
            enableHeadless: true,
            backgroundPermissionRationale:
              strings.screen.geolocationInstructions.androidPermissionsDialog,
          },
          http: {
            url: `${apiBaseUrl}geo/geofence/event`,
            headers: {
              ...defaultHeaders,
              [ApiHeaders.RainApiKey]: apiPrivateKey,
            },
            autoSync: true,
            params: {
              user_id: userId,
              device_id: device.deviceId || undefined,
              device_name: device.deviceName,
              device_os: device.platform,
            },
          },
          persistence: {
            ...BACKGROUND_GEOLOCATION_DEFAULTS.persistence,
          },
        } as GeoConfig);

        customBackgroundGeolocationLog(
          '[useGeolocation] [initBackgroundGeolocation] ready function - Enabled',
          state.enabled,
        );
        dispatch(setIsBackgroundGeolocationTrackingEnabled(state.enabled));
      } catch (err) {
        customBackgroundGeolocationLog(
          '[useGeolocation] [initBackgroundGeolocation] ready function - Error',
          err,
        );
      }
    },
    [defaultHeaders, apiBaseUrl, apiPrivateKey, dispatch, strings, userId],
  );

Relevant log output

I Have this log to confirm whats the state of the plugin at the time of the event


    BackgroundGeolocation.onGeofence(async (geofenceEvent) => {
      const settings = await BackgroundGeolocation.getState();
      customBackgroundGeolocationLog(
        '[useGeolocation] [Geofence] ',
        geofenceEvent,
        settings.http,
        settings.persistence,
      );
      dispatch(trackGeofenceTransition(geofenceEvent));

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