AFGeofencing

actual object AFGeofencing

Provides an interface for managing geofences with motion awareness and heartbeat.

This object allows starting and stopping geofencing services, and provides a Flow to observe geofence events. It utilizes Google Play Services for geofencing. It includes motion detection to adjust behavior and a heartbeat mechanism for reliability. A foreground service is used to maintain functionality when the app is in the background.

actual object AFGeofencing

AFGeofencing is the main entry point for interacting with the geofencing functionality.

It provides methods to start and stop geofencing, and a flow to observe geofence events.

Example usage:

AFGeofencing.events.onEach { event ->
when (event) {
is AFGeofenceEvent.Enter -> println("Entered geofence: ${event.geofence.id}")
is AFGeofenceEvent.Exit -> println("Exited geofence: ${event.geofence.id}")
is AFGeofenceEvent.Error -> println("Geofencing error: ${event.throwable.message}")
else -> {}
}
}.launchIn(coroutineScope)

AFGeofencing.startGeofencing(listOf(
AFGeofence(id = "home", latitude = 37.7749, longitude = -122.4194, radius = 100f),
AFGeofence(id = "work", latitude = 37.7839, longitude = -122.4013, radius = 200f)
))

Properties

Link copied to clipboard
actual val events: Flow<AFGeofenceEvent>
actual val events: Flow<AFGeofenceEvent>

Functions

Link copied to clipboard
actual fun getStatus(): AFGeofencingStatus
Link copied to clipboard
actual fun hasPermissions(): Boolean
actual fun hasPermissions(): Boolean
Link copied to clipboard
actual fun start(geofences: List<AFGeofence>): AFGeofencingResult

Starts the geofencing service with the given list of geofences. It checks for permissions, Google Play Services availability, and location settings. It starts motion monitoring and a foreground service for reliability.

actual fun start(geofences: List<AFGeofence>): AFGeofencingResult
Link copied to clipboard
actual fun stop(): AFGeofencingResult

Stops the geofencing service. It removes all registered geofences, stops motion monitoring, the foreground service, and heartbeats.

actual fun stop(): AFGeofencingResult
Link copied to clipboard
fun subscribeToGeofencingEvents(onEvent: (AFGeofenceEvent) -> Unit, onError: (Throwable) -> Unit = {}, onComplete: () -> Unit = {}): FlowSubscription

Subscribe to AFGeofencing events using callbacks. Works fine from Swift and Objective-C without async/await.

Link copied to clipboard
fun updateGeofences(newGeofences: List<AFGeofence>)

Replaces the current set of monitored geofences with a new list. If geofencing is not active, this call is ignored.