flutter_background_geolocation
flutter_background_geolocation copied to clipboard
[Bug]: bg.BackgroundGeolocation.getCurrentPosition() does not return location immediately, when desired accuracy is reached
Required Reading
- [x] Confirmed
Plugin Version
4.12.0
Flutter Doctor
[✓] Flutter (Channel stable, 3.32.4, on macOS 15.5 24F74 darwin-arm64, locale en-US) [429ms]
• Flutter version 3.32.4 on channel stable at /Users/chris/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6fba2447e9 (2 days ago), 2025-06-12 19:03:56 -0700
• Engine revision 8cd19e509d
• Dart version 3.8.1
• DevTools version 2.45.1
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,524ms]
• Android SDK at /Users/chris/Library/Android/sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [947ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16F6
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [9ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.3) [9ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
[✓] VS Code (version 1.101.0) [7ms]
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.112.0
[✓] Connected device (4 available) [6.1s]
• Chris’s iPhone (wireless) (mobile) • 00008130-000970383EE0001C • ios • iOS 18.5 22F76
• iPhone 16e (mobile) • 4D1730BE-A1FC-4AB7-AC31-3E40CB90C655 • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-4 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.5 24F74 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 137.0.7151.104
[✓] Network resources [263ms]
• All expected network resources are available.
• No issues found!
Mobile operating-system(s)
- [x] iOS
- [ ] Android
Device Manufacturer(s) and Model(s)
iPhone 15 Pro
Device operating-systems(s)
18.5
What happened?
I set samples to 100 and desiredAccuracy to 10. It keeps sampling even though it already fetched a sample with the desired accuracy.
bg.Location location = await bg.BackgroundGeolocation.getCurrentPosition(desiredAccuracy: 10, samples: 100, persist: false);
Plugin Code and/or Config
await bg.BackgroundGeolocation.ready(
bg.Config(
reset: true,
locationAuthorizationRequest: 'Always',
backgroundPermissionRationale: bg.PermissionRationale(
title: 'Allow App to access your location in the background?',
message: 'Your background location data will never leave your device!',
positiveAction: 'Allow',
negativeAction: 'Cancel',
),
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 50.0,
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
disableLocationAuthorizationAlert: true,
disableMotionActivityUpdates: false,
),
);
Relevant log output
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 53 of 100 (88 ms old)
╚═══════════════════════════════════════════════════════════
flutter: [location] - [Location {uuid: 5532F1A5-93B8-4B7E-8A1D-12BA79A20B2A, odometer: 10.4, sample: true, extras: {}, age: 89, timestamp: 2025-06-04T14:26:52.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.19315895413763, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.270690108708024, accuracy: 2.0, altitude_accuracy: 9.77, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0
╚═══════════════════════════════════════════════════════════
📍<+51.27069009,+7.19315900> +/- 2.00m (speed 0.00 mps / course -1.00) @ 04.06.2025, 16:26:53 Central European Summer Time
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 54 of 100 (99 ms old)
╚═══════════════════════════════════════════════════════════
flutter: [location] - [Location {uuid: 590C88B9-CA9B-46AF-952E-C24C5E70181A, odometer: 10.4, sample: true, extras: {}, age: 99, timestamp: 2025-06-04T14:26:53.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.193159000042946, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.270690087264434, accuracy: 2.0, altitude_accuracy: 9.67, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
📍<+51.27069003,+7.19315913> +/- 2.00m (speed 0.00 mps / course -1.00) @ 04.06.2025, 16:26:54 Central European Summer Time
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 55 of 100 (94 ms old)
╚═══════════════════════════════════════════════════════════
flutter: [location] - [Location {uuid: 078EDFE7-83F6-4251-88A0-15C158679349, odometer: 10.4, sample: true, extras: {}, age: 94, timestamp: 2025-06-04T14:26:54.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.193159132594226, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.27069002534619, accuracy: 2.0, altitude_accuracy: 9.45, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
📍<+51.27068998,+7.19315924> +/- 2.00m (speed 0.00 mps / course -1.00) @ 04.06.2025, 16:26:55 Central European Summer Time
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 56 of 100 (93 ms old)
╚═══════════════════════════════════════════════════════════
flutter: [location] - [Location {uuid: D2FA57EC-F502-4D70-8109-9AB1C1F71700, odometer: 10.4, sample: true, extras: {}, age: 93, timestamp: 2025-06-04T14:26:55.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.19315923510786, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.27068997745934, accuracy: 2.0, altitude_accuracy: 9.26, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
📍<+51.27068850,+7.19316239> +/- 2.00m (speed 0.00 mps / course -1.00) @ 04.06.2025, 16:26:56 Central European Summer Time
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 57 of 100 (94 ms old)
╚═══════════════════════════════════════════════════════════
flutter: [location] - [Location {uuid: 58FDC22A-F94C-481C-9A67-97DAD97E7A28, odometer: 10.4, sample: true, extras: {}, age: 94, timestamp: 2025-06-04T14:26:56.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.193162393829543, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.27068850193614, accuracy: 2.0, altitude_accuracy: 9.52, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
📍<+51.27068849,+7.19316241> +/- 2.00m (speed 0.00 mps / course -1.00) @ 04.06.2025, 16:26:57 Central European Summer Time
╔═══════════════════════════════════════════════════════════
║ -[LocationManager locationManager:didUpdateLocations:] Sample 58 of 100 (93 ms old)
╚═══════════════════════════════════════════════════════════
flutter: [location] - [Location {uuid: 206D7102-0AFF-434C-8953-435E0D281F38, odometer: 10.4, sample: true, extras: {}, age: 93, timestamp: 2025-06-04T14:26:57.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.1931624121650515, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.27068849337114, accuracy: 2.0, altitude_accuracy: 9.46, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
⚠️-[LocationManager onTimeout:] Using last-known location <+51.27068849,+7.19316241> +/- 2.00m (speed 0.00 mps / course -1.00) @ 04.06.2025, 16:26:57 Central European Summer Time
🔴-[LocationManager stopUpdatingLocation] OFF
✅-[LocationManager onTimeout:] Returning best available location sample
🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 3.8
flutter: [location] - [Location {uuid: 0949D1E7-B629-4850-B25D-1799AAC4EBCA, odometer: 10.4, extras: {}, age: 142, timestamp: 2025-06-04T14:26:57.999Z, battery: {level: 1.0, is_charging: true}, coords: {speed_accuracy: 0.31, speed: 0.0, longitude: 7.1931624121650515, ellipsoidal_altitude: 219.41, floor: null, heading_accuracy: -1.0, latitude: 51.27068849337114, accuracy: 2.0, altitude_accuracy: 9.46, altitude: 173.82, heading: -1.0}, is_moving: false, activity: {type: still, confidence: 100}}]
App is being debugged, do not track this hang
Hang detected: 2.79s (debugger attached, not reporting)
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0
╚═══════════════════════════════════════════════════════════
Fixedi n 4.16.11
Thanks