transistorsoft / flutter_background_geolocation

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

Ambiguous/random location coordinate values #1379

Open Hammad335 opened 1 week ago

Hammad335 commented 1 week ago

Your Environment

[✓] Flutter (Channel stable, 3.19.0, on macOS 14.6 23G80 darwin-arm64 (Rosetta), locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] Connected device (2 available)
[✓] Network resources 

Expected Behavior

Library location coordinates should be correct

Actual Behavior

Library location coordinates are obscure

Context

We are using geofencing for stores/marts to track salesperson attendance based on the time they log in and out of the store. Occasionally, a salesperson reports that even though they were in the store all day, "exit" and then "enter" events are triggered, causing the time between exit and re-entry to be deducted from their assigned shift time.

To verify whether the salesperson was actually inside the store during their shift, we upload plugin logs to Firestore and compare the distance between the store's coordinates and the user's location coordinates. However, sometimes the user location coordinates returned by the geofence library are incorrect or appear as random characters, as shown below:

Check the values of lat/lng :

Sample 1 :

╔═════════════════════════════════════════════ ║ getCurrentPosition LocationResult: 6 (1019ms old) ╠═════════════════════════════════════════════ ╟─ 📍 Location[fused 25** 67** hAcc=15 et=+29d19h18m55s99ms alt=-17.799999237060547 vel=1.1441602 bear=159.26715 vAcc=2 sAcc=0 bAcc=45 {Bundle[{}]}], time: 1731309516106 11-11 12:18:37.127 DEBUG [TSGeofenceManager setLocation] isMoving: true | stateChanged: false | timerExpired: false | elapsed: 0 11-11 12:18:37.129 INFO [TSLocationManager onSingleLocationResult] 🔵 Acquired current position 11-11 12:18:37.129 DEBUG [TSLocationManager a] Median accuracy: 15.349 11-11 12:18:37.132 INFO [SQLiteLocationDAO persist] ✅ INSERT: b71c3960-fbbf-4258-b99f-77d5ffa97bd6 11-11 12:18:37.184 DEBUG [TSLocationManagerActivity a] locationsettings 11-11 12:18:37.238 DEBUG [TSLocationManagerActivity c] eventCount: 0 11-11 12:18:37.298 DEBUG [AbstractService f]

Sample 2:

╔═════════════════════════════════════════════ ║ getCurrentPosition LocationResult: 1 (106238ms old) ╠═════════════════════════════════════════════ ╟─ 📍 Location[fused E:Gf+V9tox5AGLowkof6i1VvWzFQbDRPvQTiWxiwq77nX6wAN4KYH3ul5Eo1zzOnPil6cu5L2OLzueMNigR+fOMwQ2IeVse+w8vSx1rI5p/Z9om4hexkq+1hS9p7WIdMFCAjus9oAznFXW/q2FykoTgVejIG0bbuYjqRNvTvZHT0lPy+p7i7RGSIHn3JOlcjsSS0vTiqAoV7StCapE1paxQrw5stSBFNiZ8iObq9As2JsCyX2j1m2lRjm62l4GtNUR/r2suhl2NzW3GW8rB6Mdqjz6i0ADrQsnYrpj7TCaJU2hc/5D3F20aV0CG/h4hwMfblVl4NziaV247bdHMq5otQ== hAcc=100.0 et=+7d22h2m34s867ms alt=-5.900000095367432 vAcc=100.0 {Bundle[{}]}], time: 1731412165053 11-12 16:51:11.297 INFO [TSLocationManager onSingleLocationResult] 🔵 Acquired current position 11-12 16:51:11.298 DEBUG [TSLocationManager a] Median accuracy: 100.0 11-12 16:51:11.307 INFO [SQLiteLocationDAO persist] ✅ INSERT: 5e51a6b6-50ea-4c2d-b2cd-b925474008be 11-12 16:51:11.328 DEBUG [TSGeofenceManager$e a] ℹ️ GeofencingClient addGeofences SUCCESS 11-12 16:51:11.330 INFO [ActivityRecognitionService start] 🎾 Start motion-activity updates 11-12 16:51:11.333 DEBUG [TSGeofenceManager d] ℹ️ Persist monitored geofences: [Geofence] 11-12 16:51:11.334 DEBUG [TSGeofenceManager$e a]

Sample 3:

╔═════════════════════════════════════════════ ║ GeofencingService: Proximity evaluator ╠═════════════════════════════════════════════ ╟─ 📍 Location[fused M:0,0,11426,-14447 hAcc=16.856 et=+6d15h40m40s631ms alt=-2.3000001907348633 vAcc=8.422104 vel=0.53491306 sAcc=1.6037768 bear=289.47748 bAcc=5.964135], age: 1553ms, time: 1731302850817 11-11 10:27:32.371 DEBUG [AbstractService a] ⚙️︎ FINISH [GeofencingService startId: 1, eventCount: 0, sticky: false] 11-11 10:27:32.373 DEBUG [TSGeofenceManager$e a] ℹ️ GeofencingClient addGeofences SUCCESS 11-11 10:27:32.373 DEBUG [TSGeofenceManager d] ℹ️ Persist monitored geofences: [Geofence] 11-11 10:27:32.373 DEBUG [TSGeofenceManager$e a]

Debug logs

christocracy commented 1 week ago

But sometimes user-location-coordinates we get from geofence-lib are ambiguous or random characters as shown below

I’ve never seen that before. The logged data are from Location.toString() but what does the actual received data look like?

Realme C21Y

Realme devices are some of the most messed up Android devices out there.

Hammad335 commented 1 week ago

I’ve never seen that before. The logged data are from Location.toString() but what does the actual received data look like?

We upload the library logs to Firestore when a salesperson completes shift for the day. The logs are retrieved using bg.Logger.getLog(), which returns logs in string format. The 'Samples' above are extracted from these string logs.

Realme devices are some of the most messed up Android devices out there.

Even when no geofence events are triggered from the start to the stop of the plugin, the location coordinates sometimes appear ambiguous. Could it be that the geofence library is not correctly storing the location coordinates in the local database, while the phone itself is providing accurate coordinates?

christocracy commented 1 week ago

Forget about what you see in the logs. I’ve never seen junk like that in over 10 years. That’s Realme responsible for that messed up logging.

Could it be that the geofence library is not correctly storing the location coordinates in the local database

Absolutely not.

even though they were in the store all day, "exit" and then "enter" events are triggered

it’s not unusual that an inaccurate location can cause a geofence event to fire (eg if the device’s location api cannot provide a location from GPS or Wifi, the last alternative is from cell tower). Particularly with low quality devices, such as Realme.

the OS is completely responsible for monitoring and firing geofences. The plug-in is only the mailman.

what radius are you providing your geofences? Increase the radius to lower the number of “false positive” events.