Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help Wanted]: No location received when stopped #312

Open
2 of 3 tasks
Swaghubinger opened this issue Mar 4, 2025 · 3 comments
Open
2 of 3 tasks

[Help Wanted]: No location received when stopped #312

Swaghubinger opened this issue Mar 4, 2025 · 3 comments

Comments

@Swaghubinger
Copy link

Swaghubinger commented Mar 4, 2025

Required Reading

  • Confirmed

Plugin Version

6.1.0

Mobile operating-system(s)

  • iOS
  • Android

What do you require assistance about?

We have a problem where we only get the second to last location at the end of the route. So when the car is parked we don't get the location where the car is parked, instead the last location we get is when the car was still driving.
Usually this is a few hundred meters away and still at speed. We have some logic bound to when a car is stopped, and this never triggers now.

[Optional] Plugin Code and/or Config

Config comes from a config page in the App, and we tried a few different configurations. This is one of the configurations where we had this issue

const config = {
    distanceFilter: 10,
    elasticityMultiplier: 10,
    disableElasticity: false,
    locationUpdateInterval: 0,
    useSignificantChangesOnly: false,
    speedJumpFilter: 300,
    stopOnStationary: false,
    stopTimeout: 5,
    disableStopDetection: true,
    allowIdenticalLocations: false,
    deferTime: 1000 * 60,
    triggerOnActivity: true,
    motionTriggerDelay: 0,
    autoSyncThreshold: 0,
    batchSync: false,
    logMaxDays: 3,
    maxDaysToPersist: 3,
    maxRecordsToPersist: -1,
    heartbeatInterval: 60,
    sendOnHeartbeat: true,
    sendOnActivityChange: true,
    sendOnMotionChange: true,
    debug: false,
    apiEndpointBase: environment.production ? 'prod' : 'qa',
  }

await BackgroundGeolocation.ready({
      backgroundPermissionRationale: {
        message: ""
      },

      // Customized Config
      distanceFilter: config.distanceFilter,
      elasticityMultiplier: config.elasticityMultiplier,
      disableElasticity: config.disableElasticity,
      locationUpdateInterval: config.locationUpdateInterval,
      useSignificantChangesOnly: config.useSignificantChangesOnly,
      speedJumpFilter: config.speedJumpFilter,
      allowIdenticalLocations: config.allowIdenticalLocations,
      triggerActivities: config.triggerOnActivity ? 'in_vehicle' : undefined,
      motionTriggerDelay: config.motionTriggerDelay,
      stopOnStationary: config.stopOnStationary,
      stopTimeout: config.stopTimeout,
      disableStopDetection: config.disableStopDetection,
      deferTime: config.deferTime,
      autoSyncThreshold: config.autoSyncThreshold,
      batchSync: config.batchSync,
      logMaxDays: config.maxDaysToPersist,
      maxDaysToPersist: config.maxDaysToPersist,
      maxRecordsToPersist: config.maxRecordsToPersist,
      heartbeatInterval: config.heartbeatInterval,

      // Fixed Config
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      geofenceModeHighAccuracy: true,
      autoSync: true,
      enableTimestampMeta: true,
      foregroundService: true,
      notification: {
        title: 'Title',
        text: 'Text',
        sticky: true,
        color: '#E61B5B',
        channelName: 'Channel',
        channelId: 'pos-tracking',
        priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_MAX,
      },
      debug: config.debug,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      stopOnTerminate: false,
      startOnBoot: true,
      url: this.envService.getApiEndpoint(config.apiEndpointBase),
      headers: {
        Authorization: 'Bearer ' + this.locationDataService.apiKey
      },
      params: {
        licensePlate: this.locationDataService.licensePlate,
        deviceId: this.locationDataService.deviceId,
        version: this.versionService.appVersion$.value,
        moving: this.moveState
      }
    });
    await BackgroundGeolocation.start();

    BackgroundGeolocation.onHttp(response => {
      if (response.success) {
        this.locationDataService.setConnectionSuccess();
      } else {
        this.locationDataService.setConnectionError(response.status, response.responseText);
      }
    });

    if(config.sendOnHeartbeat) {
      BackgroundGeolocation.onHeartbeat(async () => {
        await BackgroundGeolocation.getCurrentPosition({
          persist: true,
        });
        await BackgroundGeolocation.sync();
      })
    }
    if(config.sendOnMotionChange) {
      BackgroundGeolocation.onMotionChange(async (ev) => {
        await BackgroundGeolocation.getCurrentPosition({
          persist: true,
        });
        await BackgroundGeolocation.sync();
      })
    }
    if(config.sendOnActivityChange) {
      BackgroundGeolocation.onActivityChange(async (ev) => {
        await BackgroundGeolocation.getCurrentPosition({
          persist: true,
        });
        await BackgroundGeolocation.sync();
      })
    }

[Optional] Relevant log output

@christocracy
Copy link
Member

BackgroundGeolocation.onMotionChange(async (ev) => {
        await BackgroundGeolocation.getCurrentPosition({
          persist: true,
        });
        await BackgroundGeolocation.sync();
      })

Why are you calling .getCurrentPosition in .onMotionChange? The .onMotionChange event provides you with the location (ev.location)

@Swaghubinger
Copy link
Author

I thought i could force a location this way, since we were missing a location when stopping

@Swaghubinger
Copy link
Author

I think we found the core problem we have. It seems the dynamic elasticity is calculated with the last valid location. But if at this position the car was still at a relatively high speed, the elasticity calculates for example that the next position should be 400 meter further. But if the car then stops within these 400 meters, no location is recorded.

Maybe you could look into re-calculating the elasticity when the speed changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants