LocationManager

Streams device location updates and exposes the last known Location.

Create a LocationManager via createLocationManager, or with rememberLocationManager in Compose. For an API that handles permissions and subscriptions automatically in Compose, use rememberLocation. A LocationManager stops updating when it is closed.

val manager = createLocationManager(LocationManagerOptions(accuracy = LocationAccuracy.HIGH))
if (manager.requestLocationPermission()) {
manager.addOnLocationChangedListener { location -> println("At ${location.latitude}, ${location.longitude}") }
manager.startUpdating()
}

See also

Properties

Link copied to clipboard

The last known Location, or null if no location is known.

Link copied to clipboard

The current location permission status.

Functions

Link copied to clipboard
abstract fun addOnLocationChangedListener(callback: (location: Location) -> Unit): ListenerSubscription

Adds a callback to be called whenever the current Location changes.

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract suspend fun requestLocationPermission(): Boolean

Requests the location permission.

Link copied to clipboard
abstract suspend fun startUpdating()

Starts location updates.

Link copied to clipboard
abstract suspend fun stopUpdating()

Stops location updates.