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

Location Tracking Issue in Foreground Mode with flutter_background_geolocation #1407

Open
AniketStemmOne opened this issue Jan 14, 2025 · 4 comments

Comments

@AniketStemmOne
Copy link

Your Environment

  • Plugin version: flutter_background_geolocation: ^4.13.5
  • Platform: Android
  • OS version: 14
  • Device manufacturer / model: OnePlus Nord CE 2 Lite (CPH2381)
  • Flutter info (flutter doctor):
  • Plugin config:
    flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [√] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.22631.4602], locale en-IN)
    [√] Windows Version (Installed version of Windows is version 10 or higher)
    [√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    [√] Chrome - develop for the web
    [√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2019 16.11.20)
    [√] Android Studio (version 2021.3)
    [√] Android Studio (version 2022.2)
    [√] VS Code (version 1.96.2)
    [√] Connected device (4 available)
    [√] Network resources
bg.BackgroundGeolocation.ready(bg.Config(  
  desiredAccuracy: bg.Config.DESIRED_ACCURACY_MEDIUM,  
  distanceFilter: 300,  
  enableHeadless: true,  
  stopOnTerminate: false,  
  autoSync: true,  
  geofenceModeHighAccuracy: false,  
  startOnBoot: true,  
  debug: false,  
  desiredOdometerAccuracy: 10,  
  geofenceInitialTriggerEntry: true,  
  logLevel: bg.Config.LOG_LEVEL_VERBOSE,  
  disableStopDetection: true,  
  pausesLocationUpdatesAutomatically: false,  
  heartbeatInterval: 300,  
  preventSuspend: true,  
  motionTriggerDelay: 1000,  
  geofenceProximityRadius: 100,  
  activityRecognitionInterval: 1000,  
));  

Expected Behavior

Location tracking should work consistently, regardless of whether the app is in the foreground or background.

Actual Behavior

Location tracking stops when the app is in the foreground and actively in use. No logs or location data are generated during this time.

Steps to Reproduce

  1. Run the app on a OnePlus Nord CE 2 Lite device.
  2. Start location tracking using the provided configuration.
  3. Use the app actively or switch to other apps while traveling.
  4. Observe that location tracking stops and no logs are generated.

Context

Trying to track real-time locations reliably for an active user.

Debug logs

Logs
  [c.t.l.l.TSLocationManager setOdometer] 
I/TSLocationManager(28506):   ℹ️  setOdometer: 0.0, isMoving: false
D/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] 
D/TSLocationManager(28506):   ℹ️  Clear last odometer location
I/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] 
I/TSLocationManager(28506): ╔═════════════════════════════════════════════
I/TSLocationManager(28506): ║ getCurrentPosition LocationResult: 1 (26169ms old)
I/TSLocationManager(28506): ╠═════════════════════════════════════════════
I/TSLocationManager(28506): ╟─ 📍  Location[fused 18.56****,73.92**** hAcc=20.0 et=+3d14h58m40s433ms alt=553.7000122070312 vAcc=1.0], time: 1736837518835
D/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] Median accuracy: 20.0
D/TSLocationManager(28506): [c.t.l.u.LocationAuthorization withPermission] 
D/TSLocationManager(28506):   ℹ️  LocationAuthorization: Permission granted
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  start [LocationRequestService  startId: 1, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.l.SingleLocationRequest startUpdatingLocation] 
I/TSLocationManager(28506):   🔵  [SingleLocationRequest start, action: 2, requestId: 1]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 1, eventCount: 0, sticky: true]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  2:1 [LocationRequestService  startId: 2, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.s.LocationRequestService b] 
I/TSLocationManager(28506):   ℹ️  Location availability: false
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 2, eventCount: 0, sticky: true]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  2:1 [LocationRequestService  startId: 3, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.s.LocationRequestService b] 
I/TSLocationManager(28506):   ℹ️  Location availability: true
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 3, eventCount: 0, sticky: true]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  2:1 [LocationRequestService  startId: 4, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] 


 ╔═════════════════════════════════════════════
I/TSLocationManager(28506): ║ getCurrentPosition LocationResult: 1 (1181ms old)
I/TSLocationManager(28506): ╠═════════════════════════════════════════════
I/TSLocationManager(28506): ╟─ 📍  Location[fused 18.56****,73.92**** hAcc=20.0 et=+3d14h59m6s751ms alt=553.7000122070312 vAcc=1.0], time: 1736837545153
D/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] Median accuracy: 20.0
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 4, eventCount: 0, sticky: true]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  2:1 [LocationRequestService  startId: 5, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.s.LocationRequestService b] 
I/TSLocationManager(28506):   ℹ️  Location availability: false
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 5, eventCount: 0, sticky: true]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  2:1 [LocationRequestService  startId: 6, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.s.LocationRequestService b] 
I/TSLocationManager(28506):   ℹ️  Location availability: true
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 6, eventCount: 0, sticky: true]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   🎾  2:1 [LocationRequestService  startId: 7, eventCount: 1]
I/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] 
I/TSLocationManager(28506): ╔═════════════════════════════════════════════
I/TSLocationManager(28506): ║ getCurrentPosition LocationResult: 1 (2421ms old)
I/TSLocationManager(28506): ╠═════════════════════════════════════════════
I/TSLocationManager(28506): ╟─ 📍  Location[fused 18.56****,73.92**** hAcc=20.0 et=+3d14h59m11s768ms alt=553.7000122070312 vAcc=1.0 vel=0.0039497516 sAcc=1.5], time: 1736837550170
I/TSLocationManager(28506): [c.t.l.l.TSLocationManager onSingleLocationResult]

[c.t.l.l.TSLocationManager onSingleLocationResult] 
I/TSLocationManager(28506):   🔵  Acquired current position
D/TSLocationManager(28506): [c.t.l.l.TSLocationManager a] Median accuracy: 20.0
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 7, eventCount: 0, sticky: false]
D/TSLocationManager(28506): [c.t.l.service.AbstractService b] 
D/TSLocationManager(28506):   🎾  STOP [LocationRequestService startId: 8, eventCount: 1]
D/TSLocationManager(28506): [c.t.l.service.AbstractService a] 
D/TSLocationManager(28506):   ⚙️︎   FINISH [LocationRequestService startId: 8, eventCount: 0, sticky: false]
@christocracy
Copy link
Member

The plug-in operates no differently in background vs foreground.

have you read the wiki “Philosophy of Operation”?

distanceFilter: 300,

This is rather high.

You should be testing outside with real movement.

@christocracy
Copy link
Member

christocracy commented Jan 14, 2025

geofenceProximityRadius: 100,

If you’re not using geofences (and monitoring < 100 geofences), this option is not used. 100 is also in invalid value, as the plug-in imposes a minimum value of 1000.

@AniketStemmOne
Copy link
Author

Is it possible for the tracking process to stop or terminate if the app is in use in the foreground and performing other operations? The tracking works fine when the app is in the background or terminated state, but not when it is active in the foreground. ??

@christocracy
Copy link
Member

Is it possible for the tracking process to stop or terminate if the app is in use in the foreground and performing other operations?

Not automatically, no. The plugin doesn't care if your app is in the foreground or background. It does not change its behaviour on app state. It only cares if the device moving or stationary.

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