πGeolocation Overview
Geolocation includes the following features:
Track a user's location
Get the current location
Customize the accuracy of the tracking
Android and iOS support, using built-in services.
Built-in Location permission handling
Quickstart
Include the required dependencies for your targets, see All Dependencies.
Create the Geolocator
Creating a geolocator depends on your platform, but in the simplest use-case of an Android & iOS only targets. You can do something like this:
val geolocator: Geolocator = Geolocator.mobile()
Get current location
Getting the current location is simple, just call:
val result: GeolocatorResult = geolocator.current()
// Handle the result:
when (result) {
is GeolocatorResult.Success -> {
// Do something with result.location
}
is GeolocatorResult.Error -> when(result) {
is GeolocatorResult.NotSupported -> TODO()
is GeolocatorResult.NotFound -> TODO()
is GeolocatorResult.PermissionError -> TODO()
is GeolocatorResult.GeolocationFailed -> TODO()
}
}
Or if you only care about the result:
val location: Location? = geolocator.currentOrNull()
Last updated
Was this helpful?