transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
639 stars 235 forks source link

Odometer is always 0.0, except in one rare case. #1342

Open irjayjay opened 1 month ago

irjayjay commented 1 month ago

Your Environment

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.

christocracy commented 1 month ago

Go outside and test on a real device.

irjayjay commented 1 month ago

If you read what I posted, you'll see that I did. In fact, I drove all the way to the shops and back and the odometer ended up on 0.0.

In another issue on here you told the person that this library is compatible with location spoofing, so it's interesting that you're telling me to go outside now.

irjayjay commented 1 month ago

I just tried again. Walked with my laptop and phone connected in debug mode. I could hear the debug audio prompts from the geolocation library, every few meters of movement. It made that iPhone message sound, to indicate movement about 5 times. Finally I triggered to fetch the odometer and it was 0.0 again.

I have a breakpoint set on setOdometer, it never triggered, so it's not that it gets set to 0.0.

I don't understand how the library is getting location updates, yet the odometer doesn't update.

christocracy commented 1 month ago

I suggest you fetch the logs and have a look at them.

see api docs “.emailLog”

irjayjay commented 1 month ago

I figured something out. I tested with a distanceFilter of 3.0 yesterday. But disableElasticity was false. Later I disabled elasticity and it still didn't work, because at that time I think distanceFilter was 10.0.

I had this all work for me with elasticity enabled and distanceFilter 10.0 the other day, but I don't know how. I was walking at a normal pace and according to the calculations, only if I walked faster than 2.5m/s, then it would round up to 5m/s, which would count as 1 x distanceFilter meters travelled. So any time I travel less than 2.5m/s, it's like I'm not moving.

I'd say it should start off with 10.0, then add 10.0 for every 5m/s of speed from there on, otherwise you'll only record something when running or in a vehicle.

So I hit the sweet spot where no location updates would happen. Still weird that I could hear location updates earlier this morning, yet odometer stayed on 0.

Hope this helps future travellers.

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity.