Closed emlil closed 11 months ago
locationAuthorizationRequest: "WhenInUse",
Both iOS and Android require Always
authorization for geofencing.
@christocracy even though it is set to this in config, the testing has been done with the permission set to always. Is this setting still relevant then?
Show me the vertices of this polygon SITE0p7gzujjd1675331538234
11-09 12:28:50.414 INFO [GeofencingService a]
╔═════════════════════════════════════════════
║ Geofencing Event: ENTER
╠═════════════════════════════════════════════
╟─ ENTER containing geofence of Polygon: SITE0p7gzujjd1675331538234 buffer
╚═════════════════════════════════════════════
╔═════════════════════════════════════════════
║ isInPolygon: 📍 60.38281687922973, 5.308061099753924, acy: 3.9m
╠═════════════════════════════════════════════
11-09 12:28:52.027 DEBUG [TSGeofence isLocationInPolygon] --> SITE0p7gzujjd1675331538234 buffer: 0.0%
You can see the polygon evaluator operating in the logs here, reporting that 0.0%
of the current location resides within the polygon.
The way the polygon evaluator operates is by drawing a circle around the current location of radius accuracy
meters (in this case 3.9m
, then computing 16 points around that circle. When 40%
of the 16 points are within the polygon, the ENTER
event will be fired.
I suspect you've created too small of a polygon.
Here are some images to show how this works.
accuracy
meters.accuracy
circle" (16 * 22.5 = 360
)ENTER
ed the geofence.EXIT
to fire.In the first image, there are only 5 of 16 "boundary points" within the polygon. 5 / 16 = ~31%
. The location is not considered to have entered the polygon.
In the next image, there are 9 of 16 "boundary points" within the polygon. The current location is considered to have ENTER
ed the polygon: 9 / 16 = ~56%
So, when you see this in the logs:
╔═════════════════════════════════════════════
║ isInPolygon: 📍 60.38281687922973, 5.308061099753924, acy: 3.9m
╠═════════════════════════════════════════════
[TSGeofence isLocationInPolygon] --> SITE0p7gzujjd1675331538234 buffer: 0.0%
acy 3.9m
: This is the radius of the blue circle shown above. There are 16 "white boundary points" calculated around that circleSITE0p7gzujjd1675331538234 buffer: 0.0%
: This line shows the percentage of "white boundary points" that are within your polygon. In this case, none (0.0%
).Here are the vertices
[[60.38230286513362, 5.303395185529516], [60.38244023767629, 5.303405600991172], [60.3825337587921, 5.303609473409488], [60.382657036853956, 5.304281134786446], [60.382660543085436, 5.3045132171610945], [60.38252931158423, 5.305388726423183], [60.38246441079633, 5.305575204807774], [60.382357382464, 5.305646751455249], [60.38195738377663, 5.305646751455249], [60.38184236927869, 5.305562495717216], [60.38178066741885, 5.305348783541836], [60.38173559733897, 5.304851465750848], [60.38173265574079, 5.304783154512104], [60.38173530692368, 5.304071259999923], [60.38176786945291, 5.303865262316839], [60.38185249410989, 5.303733143865392], [60.38230286513362, 5.303395185529516]]
Btw, you don't need to "close a polygon" by ending your vertices with a copy of the first [60.38230286513362, 5.303395185529516]
. Polygon's are auto-closed.
I've now updated the geofence, its almost three times the original size. And i walked through the site
Here's the vertices
(
[60.38318063075226, 5.30255789249031]
[60.383318509253094, 5.302661544592356]
[60.38337192056702, 5.302938857846105]
[60.383336319758925, 5.304375378182343]
[60.383327071706326, 5.306670196084874]
[60.383265112133905, 5.306941907724499]
[60.38312341027312, 5.307027521072812]
[60.3816682604143, 5.306630554138608]
[60.38156787198031, 5.306532581740304]
[60.38151535441579, 5.306333660172467]
[60.38138544531188, 5.3048492894639985]
[60.38138327892702, 5.304756546992615]
[60.38144955914681, 5.303100514907193]
[60.38150253811331, 5.302870899386415]
[60.38161678363834, 5.302767104793472]
[60.38318063075226, 5.30255789249031]
)
In the log this time there are no mentions of the polygon for SITE0p7gzujjd1675331538234 except for in creation of the polygon. There are a lot of events for another site:
11-09 17:38:26.629 DEBUG [PolygonGeofencingService c]
╔═════════════════════════════════════════════
║ isInPolygon: 📍 60.3820087, 5.3050213, acy: 3.91m
╠═════════════════════════════════════════════
11-09 17:38:26.630 DEBUG [TSGeofence isLocationInPolygon] --> SITEneyk7lz741686640742230 buffer: 0.0%
But they are checking a location thats inside the first mentioned polygon: SITE0p7gzujjd1675331538234
I see unknown problems with the plugin's calculation of the "minimum enclosing circle" (the native circular geofence that encloses your polygon).
11-09 17:34:48.824 DEBUG [TSGeofence$Builder build] [MiniBall] Minimum Enclosing Circle: 0.0 / 0.0, radius0.0
11-09 17:34:48.825 DEBUG [TSGeofence$Builder build] [MiniBall] Minimum Enclosing Circle: 0.0 / 0.0, radius1.17E-321
When I create a Polygon using your coordinates:
[60.38318063075226, 5.30255789249031]
[60.383318509253094, 5.302661544592356]
[60.38337192056702, 5.302938857846105]
[60.383336319758925, 5.304375378182343]
[60.383327071706326, 5.306670196084874]
[60.383265112133905, 5.306941907724499]
[60.38312341027312, 5.307027521072812]
[60.3816682604143, 5.306630554138608]
[60.38156787198031, 5.306532581740304]
[60.38151535441579, 5.306333660172467]
[60.38138544531188, 5.3048492894639985]
[60.38138327892702, 5.304756546992615]
[60.38144955914681, 5.303100514907193]
[60.38150253811331, 5.302870899386415]
[60.38161678363834, 5.302767104793472]
[60.38318063075226, 5.30255789249031]
My logs show:
[MiniBall] Minimum Enclosing Circle: 60.3826828841048 / 5.304786700866407, radius 253.93713971114747
I think you must be providing bad vertices
on the device you're testing on.
This is your polygon vertices and the calculated enclosing circle:
I suggest you test your data with addGeofence and pay close attention to the MiniBall
logs calculating the enclosing circle. You should never see a latitude/longitude of 0, 0
.
[MiniBall] Minimum Enclosing Circle
Alright. I ran the app only creating a single geofence
bg.BackgroundGeolocation.addGeofence(bg.Geofence(
identifier: 'test',
vertices: [
[60.38318063075226, 5.30255789249031],
[60.383318509253094, 5.302661544592356],
[60.38337192056702, 5.302938857846105],
[60.383336319758925, 5.304375378182343],
[60.383327071706326, 5.306670196084874],
[60.383265112133905, 5.306941907724499],
[60.38312341027312, 5.307027521072812],
[60.3816682604143, 5.306630554138608],
[60.38156787198031, 5.306532581740304],
[60.38151535441579, 5.306333660172467],
[60.38138544531188, 5.3048492894639985],
[60.38138327892702, 5.304756546992615],
[60.38144955914681, 5.303100514907193],
[60.38150253811331, 5.302870899386415],
[60.38161678363834, 5.302767104793472],
[60.38318063075226, 5.30255789249031]],
notifyOnEntry: true,
notifyOnExit: true,
)
);
Creating a geofence like this gives the same result:
D/TSLocationManager( 7824): [c.t.l.g.TSGeofence$Builder build] [MiniBall] Minimum Enclosing Circle: 0.0 / 0.0, radius0.0
However, creating polygonal geofences in your example app on the same device seems to work:
D/TSLocationManager(14489): [c.t.l.g.TSGeofence$Builder build] [MiniBall] Minimum Enclosing Circle: 60.38288617717974 / 5.3080188391343945, radius60.54230040772544
The same is the case when trying it out in a basic app with only geofencing.
Sometimes the MiniBall
logs a really strange radius. Might be an int overflow?
D/TSLocationManager(11765): [c.t.l.g.TSGeofence$Builder build] [MiniBall] Minimum Enclosing Circle: 0.0 / 0.0, radius1.0E-323
Do you have any clue what our app does wrong?
Do you have any clue what our app does wrong?
Did you purchase a license for Polygon Geofencing? Are you testing your app with a "release" or "debug" build?
We've not purchased a license yet.
We are running the app in debug mode
However this message appears when we start building
[flutter_background_geolocation] Purging debug resources in release build
However this message appears when we start building
This doesn't mean your app is building for release
. This is just the plugin iterating through all variants
(debug
and release
) and adding a method.
I've added some debug output during MiniBall
process that I need to see you execute.
Please modify your pubspec.yaml
to load the plugin from the git
as follows:
dependencies:
flutter_background_geolocation:
git:
url: https://github.com/transistorsoft/flutter_background_geolocation.git
ref: miniball-error
Remove / re-add your gefence(s).
From your logs, I'm interested in seeing the new *** IS DEBUG? 1 || 0
output:
V/TSLocationManager(14881): *** IS DEBUG? 1
V/TSLocationManager(14881): [MiniBall] Circle coordinate: 60.382683, 5.304787, radius: 253.937140
V/TSLocationManager(14881): [MiniBall] squared_radius: 0.000005, corrected radius: 253.937140
V/TSLocationManager(14881): [MiniBall] isValid?: 0, error: 0.000000
Running this version provides me with
V/TSLocationManager(16555): *** IS DEBUG? 0
This is the problem. Why does your app think it's not running as a DEBUG
build? The plugin MiniBall
process purposely returns incorrect data when the app is run as a RELEASE
build without a polygon-geofencing license key.
How are you building / launching your app?
Doing print(kDebugMode);
return true though. How come this is different?
I'm using android studio and launching the app in debug mode through its UI (the debug button)
What is kDebugMode
?
Launch your app from console:
$ flutter run
What is
kDebugMode
?
Its a constant that is true if the app is built in debug mode (source)
I don't think that is necessarily related to the Android build variant. That's related to the dart
code.
Our app relies on flavors, doing flutter run --flavor staging
also returns V/TSLocationManager(19317): *** IS DEBUG? 0
$ flutter run --flavor stagingDebug
Now im doing
$ flutter run --flavor stagingDebug
running gradle task assembleStagingDebugDebug
building and installing the apk file app-stagingdebug-debug.apk
My build is very debug now but I still get V/TSLocationManager( 9134): *** IS DEBUG? 0
and D/TSLocationManager( 9134): [c.t.l.g.TSGeofence$Builder build] [MiniBall] Minimum Enclosing Circle: 0.0 / 0.0, radius: 0.0
I see a problem. I've pushed another commit to branch miniball-error
.
Do a flutter pub get
and run the following:
$ flutter run --flavor staging --debug
This seems to have solved the issue!
Your Environment
Plugin version: 4.13.4
Platform: Android
OS version: 13
Device manufacturer / model: Google Pixel 7 Pro
Flutter info (
flutter doctor
):Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.9, on macOS 14.1 23B74 darwin-arm64, locale en-NO) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 15.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.83.1) [✓] Connected device (3 available) ! Error: Browsing on the local area network for Emil iPhone . Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources
Plugin config:
background-geolocation (3).log