PolygonGeofenceService class
Service for managing polygon geofences.
This service handles:
- Adding, removing, and updating polygon geofences
- Checking if a location is inside any registered polygon
- Emitting events when polygon boundaries are crossed
Example:
final service = PolygonGeofenceService();
// Define a polygon (e.g., a parking lot)
final parkingLot = PolygonGeofence(
identifier: 'parking-lot-1',
vertices: [
GeoPoint(latitude: 37.4219, longitude: -122.0840),
GeoPoint(latitude: 37.4220, longitude: -122.0830),
GeoPoint(latitude: 37.4215, longitude: -122.0828),
GeoPoint(latitude: 37.4214, longitude: -122.0838),
],
);
await service.addPolygonGeofence(parkingLot);
// Check if a point is inside
final isInside = service.isLocationInAnyPolygon(37.4217, -122.0834);
Constructors
Properties
- count → int
-
Returns the number of registered polygon geofences.
no setter
-
events
→ Stream<
PolygonGeofenceEvent> -
Stream of polygon geofence events (enter, exit, dwell).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
polygons
→ List<
PolygonGeofence> -
Returns all registered polygon geofences.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addPolygonGeofence(
PolygonGeofence polygon) → Future< bool> - Adds a polygon geofence.
-
addPolygonGeofences(
List< PolygonGeofence> polygons) → Future<int> - Adds multiple polygon geofences.
-
dispose(
) → void - Disposes resources.
-
getContainingPolygons(
double latitude, double longitude) → List< String> - Checks if a location is inside any registered polygon.
-
getPolygonGeofence(
String identifier) → PolygonGeofence? - Gets a polygon geofence by identifier.
-
isInsidePolygon(
String identifier) → bool - Returns true if currently inside the specified polygon.
-
isLocationInAnyPolygon(
double latitude, double longitude) → bool - Returns true if the location is inside any registered polygon.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
polygonExists(
String identifier) → bool - Returns true if a polygon with the given identifier exists.
-
processLocationUpdate(
double latitude, double longitude) → void - Processes a location update and emits events for polygon boundary crossings.
-
removeAllPolygonGeofences(
) → Future< void> - Removes all polygon geofences.
-
removePolygonGeofence(
String identifier) → Future< bool> - Removes a polygon geofence by identifier.
-
resetState(
) → void - Resets the inside state for all polygons.
-
restore(
List< PolygonGeofence> polygons) → void - Initializes the service with persisted polygons.
-
setOnPersist(
PolygonGeofencePersistCallback? callback) → void - Sets a callback to persist polygon geofences.
-
toString(
) → String -
A string representation of this object.
inherited
-
updatePolygonGeofence(
PolygonGeofence polygon) → Future< bool> - Updates an existing polygon geofence.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited