locationEvents

@RequiresPermission(anyOf = ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"])
fun FusedLocationProviderClient.locationEvents(locationRequest: LocationRequest, looper: Looper = Looper.getMainLooper()): Flow<Location>

Returns a cold flow that emits device location updates using FusedLocationProviderClient.requestLocationUpdates.

The location updates start streaming ONLY when the flow is collected, and stop streaming immediately when the collector cancels or closes the subscription.

Warning: This is a cold flow wrapping a single-listener SDK callback. Concurrently subscribing multiple collectors will result in listener hijacking, and cancelling any observer will unregister the active callback completely. Always share this flow (e.g. using kotlinx.coroutines.flow.shareIn) for multi-observer configurations.

Parameters

locationRequest

The LocationRequest specifying the quality of service (e.g. interval, priority).

looper

The Looper on which the callback runs. Defaults to Looper.getMainLooper().