flutter_background_geolocation
flutter_background_geolocation copied to clipboard
Odometer is always 0.0, except in one rare case.
Your Environment
- Plugin version: 4.15.3
- Platform: Android
- OS version: 13
- Device manufacturer / model: Samsung Galaxy S20 / Nexus S emulator with Android API 34
- Flutter info (
flutter doctor
): - Plugin config:
bg.BackgroundGeolocation.ready(
bg.Config(
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 1.0,
disableElasticity: true,
stopOnTerminate: false,
startOnBoot: false,
allowIdenticalLocations: false,
foregroundService: true,
logLevel: bg.Config.LOG_LEVEL_OFF,
preventSuspend: true,
heartbeatInterval: 5,
autoSync: true,
debug: kDebugMode,
showsBackgroundLocationIndicator: true,
notification: bg.Notification(
title: APP_NAME,
text: "Background location tracking active",
color: "#ff0000",
channelName: "Location tracking",
sticky: true,
),
backgroundPermissionRationale: bg.PermissionRationale(
message: '$APP_NAME collects location data to enable task allocation'
'and driver tracking even when the app is closed or not in use',
negativeAction: "Cancel",
positiveAction: "Open Settings",
title:
"$APP_NAME only works correctly if it can access your location all the time.",
),
persistMode: bg.Config.PERSIST_MODE_LOCATION,
enableHeadless: true,
),
);
Expected Behavior
Odometer should update to a new value whenever location changes and the new value should be returned when doing either BackgroundGeolocation.getCurrentPosition() or inside the callback for BackgroundGeolocation.onLocation().
Actual Behavior
Odometer doesn't update, whether really moving a real device, or using location spoofing(Lockito), or android-emulator location spoofing. Setting distanceFilter to 1 and disableElasticity to true does not help this. In fact, onLocation() very rarely fires.
In fact, onLocation only fires when onLocation callback gets registered. I can see updated locations if I do a BackgroundGeolocation.getCurrentPosition() inside the onHeartbeat, but even this won't update the odometer. I'd expect any latest location fetch would update it.
The only workaround to get the odometer to record anything is to turn a location spoofing app (Lockito) on and off, which triggers an update onLocation too.
Steps to Reproduce
bg.BackgroundGeolocation.onLocation((bg.Location location) {
debugPrint('===ODO: ${location.odometer}');
debugPrint('===mock: ${location.mock}');
debugPrint('===coords: ${location.coords}');
});
Future.delayed(Duration(seconds:3)).then((){
bg.BackgroundGeoLocation.setOdometer(0);
});
Future.delayed(Duration(seconds:30)).then((){
bg.BackgroundGeoLocation.odometer.then((odometer) {
debugPrint('=== odometer: $odometer');
});
});
Context
Trying to record the odometer readings of a driver at the end of a trip.