AndroidLocationProvider

Foreground location from Android's location service.

Uses fused location on Android 12 and later, and an available provider matching the requested accuracy on earlier versions. LocationAccuracy.Lowest receives passive updates.

Disabled location services report LocationUnavailableReason.ServicesDisabled. Missing permission reports LocationUnavailableReason.PermissionDenied. Invalid provider registration reports LocationUnavailableReason.UnexpectedFailure.

See AndroidLocationPermissionRequester for permission request requirements.

Create the provider, request permission, and close it on the main thread.

Parameters

context

Context used to access location services.

requester

Constructors

Link copied to clipboard
constructor(context: Context)

Creates a provider with its own AndroidLocationPermissionRequester.

Properties

Link copied to clipboard

Whether this provider has a usable platform implementation, stable for its lifetime.

Link copied to clipboard
open override val backendId: String

A stable implementation name for diagnostics, when the provider declares one.

Link copied to clipboard
open override val permission: StateFlow<LocationPermission>

Current foreground location permission.

Functions

Link copied to clipboard
open override fun close()

Releases resources owned by this provider. Repeated calls have no effect.

Link copied to clipboard
open override fun requestPermission()

Starts a foreground permission request and returns immediately.

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"])
open override fun updates(request: LocationRequest = LocationRequest()): Flow<LocationEvent>

Returns a cold stream of foreground location updates.