GeofencingService class final
Monitors GeoJSON features for entry, dwell, and exit.
Supported platforms: Android and iOS.
Grant location permission before using GeofencingService.instance. Independent of MapboxMap. Features are stored on disk and remain monitored across app launches.
To get events while the app is in the background, grant "Always" location permission on iOS, and background location on Android.
Only iOS relaunches a terminated app for geofencing events. On Android, events stop when the app is terminated.
Note: iOS 18 and later requires an active service session with Always authorization. See CLServiceSession.
final service = GeofencingService.instance;
await service.addFeature(
GeofenceFeature.circle(
id: 'store',
center: Point(coordinates: Position(11.78, 48.35)),
radius: 100,
dwellTime: Duration(minutes: 10),
),
);
service.entryEvents.listen((event) => print('Entered ${event.feature.id}'));
Constructors
- GeofencingService(GeofencingPlatformInterface _impl)
Properties
-
dwellEvents
→ Stream<
GeofencingEvent> -
The user stayed inside a monitored feature for its dwell time.
no setter
-
entryEvents
→ Stream<
GeofencingEvent> -
The user entered a monitored feature.
no setter
-
errors
→ Stream<
GeofencingError> -
Problems while monitoring, such as revoked location permission or
approximate accuracy, and failures to start observing.
no setter
-
exitEvents
→ Stream<
GeofencingEvent> -
The user left a monitored feature.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addFeature(
Feature< GeometryObject> feature) → Future<String> -
Monitors
feature. Returns its id. -
clearFeatures(
) → Future< int> - Removes every monitored feature and returns how many were removed.
-
configure(
GeofencingOptions options) → Future< void> - Sets how many features the service monitors.
-
getFeature(
String identifier) → Future< GeofenceState> - The monitored feature and, while the user is inside it, when they entered.
-
getOptions(
) → Future< GeofencingOptions> - The current geofencing options.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeFeature(
String identifier) → Future< void> -
Stops monitoring
identifier. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → GeofencingService
-
The process-wide service.
final