A more accurate geofencing

This commit is contained in:
2026-02-18 20:43:33 +08:00
parent 8c1bb7646e
commit 15ce7b7a10
2 changed files with 54 additions and 10 deletions
+14 -10
View File
@@ -407,16 +407,20 @@ class _ScheduleTile extends ConsumerWidget {
),
);
final isInside = geofence.hasPolygon
? geofence.containsPolygon(position.latitude, position.longitude)
: geofence.hasCircle &&
Geolocator.distanceBetween(
position.latitude,
position.longitude,
geofence.lat!,
geofence.lng!,
) <=
geofence.radiusMeters!;
if (!geofence.hasPolygon) {
if (!context.mounted) return;
await _showAlert(
context,
title: 'Geofence missing',
message: 'Geofence polygon is not configured.',
);
return;
}
final isInside = geofence.containsPolygon(
position.latitude,
position.longitude,
);
if (!isInside) {
if (!context.mounted) return;