[Bug]: EXIT event is not triggered by startGeofences() in Android
Required Reading
- [x] Confirmed
Plugin Version
4.16.9
Flutter Doctor
[✓] Flutter (Channel stable, 3.22.1, on macOS 15.3.1 24D70 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2025.1.1)
[✓] VS Code (version 1.88.0)
[✓] Connected device (5 available)
[✓] Network resources
Mobile operating-system(s)
- [ ] iOS
- [x] Android
Device Manufacturer(s) and Model(s)
moto g7 play (XT1952-1)
Device operating-systems(s)
Android 10
What happened?
Hi @christocracy ,
I have two issues with geofence mode on Android. Everything works fine on iOS.
When I start the service with
bg.BackgroundGeolocation.start();
- The EXIT event is triggered as expected. However, when I start the service exclusively in geofence mode, the event is not triggered.
Here are the logs for two cases.
- In geofence mode, the ENTER event is not triggered correctly for a large polygon.
Note: I use Lockito to simulate the GPS position.
Thanks for your help!
Plugin Code and/or Config
bg.BackgroundGeolocation.ready(bg.Config(
reset: true,
enableHeadless: true,
foregroundService: true,
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 10.0,
notification: bg.Notification(
sticky: true,
title: "${F.title} - tracking your location",
text:
"${F.title} accessing background location to track your location, even when it's not running."),
backgroundPermissionRationale: bg.PermissionRationale(
title: "Allow {applicationName} to access this device's location even when the app is closed or not in use.",
message: "This app collects location data to change your status based on geofence.",
positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
negativeAction: 'Cancel'
),
stopOnTerminate: false,
startOnBoot: true,
debug: false,
heartbeatInterval: 60,
preventSuspend: true,
persistMode: bg.Config.PERSIST_MODE_ALL,
showsBackgroundLocationIndicator: true,
locationAuthorizationRequest: 'Always',
logLevel: bg.Config.LOG_LEVEL_VERBOSE))
.then((bg.State state) {
print('[ready] - $state');
bg.BackgroundGeolocation.startGeofences();
});
Relevant log output
Geofence events can be delayed in geofence-only mode (ie: .startGeofences()).
See API docs Config.geofenceModeHighAccuracy, which will consume more power by keeping location-services ON during geofence-only mode.
It's a well-known with Android geofences among the entire Android development ecosystem, where they sometimes fail to fire or are delay if location-services is not active.
https://issuetracker.google.com/issues/218335535
Hi, thanks for your reply. With the "geofenceModeHighAccuracy: true" option, more events seem to be triggered than before. I've read your thread. Unfortunately, it's a very poor move by the Android team to have this unreliable feature. It's great that you're trying to have workaround to keep the location-service ON. I have a question: If "geofenceModeHighAccuracy: true" still isn't good enough, do you think, that I should start the plugin with "start()"? Would that be more helpful? And how does the battery consumption compare to "geofenceModeHighAccuracy: true"?
do you think, that I should start the plugin with "start()"?
It shouldn’t make a difference.
And how does the battery consumption compare to "geofenceModeHighAccuracy: true"?
Unknown.
Hello @christocracy,
I have another problem, but it's not so big that I need to create a new ticket. On iOS, I enter the zone and receive the ENTER event. Then I close the app in the background and reopen it. The EXIT event is generated immediately, even if I'm still in the polygon. In the logs, I see that the plugin keeps throwing this error after calling ready(). do you have any ideas?
flutter: [ready] - [State enabled: true, isMoving: false, trackingMode: 0, desiredAccuracy: -1, distanceFilter: 10.0, odometer: 0.0, schedulerEnabled: false, foregroundService: null]
[Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone [Geofencing] pointInPolygon failed to find vertices for TestZone
I don't have this issue on Android. I don't look at the log, but the event isn't generated in the same test case.
Send me entire log file from .emailLog method.
I attached the log file. By the way, this only happens on the real device. I'm testing on the iPhone 14 Pro. I don't have this issue in the simulator.
Your log-file spans a period of ~7 minutes and contains no reference to the word "TestZone".
The plugin can store up to three days worth of logs.
Go do your testing to reproduce your reported issue and provide a log file containing those errors.
Forget the name TestZone. I just renamed it to hide information. The actual error logs have the same name as the log file.
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home [Geofencing] pointInPolygon failed to find vertices for 14§§§Home
I see no reference to the text "pointInPolygon failed to find vertices for " in your log-file.
I don't know why. But it appears in my flutter logs.
Post a new issue.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.