ध्रुव
Dhruva¶
Location for Kotlin Multiplatform apps. Battery-aware on Android, lifecycle-aware on iOS, crash-safe on both.
What you get¶
- One-shot fixes
- Continuous tracking
- FusedLocationProvider
- CLLocationManager
- Sealed errors
- Apache 2.0
Dhruva is a small KMP library that gives you a uniform location API across Android and iOS.
LocationTracker.getCurrentLocation()for single fixes; seeds from the platform's last known location for instant UI.LocationTracker.startTracking()returns aFlow<Location>; cancel the flow to stop tracking.- Errors are typed (
LocationError.PermissionDenied,LocationError.Timeout, etc.), never rawThrowableacross the bridge.
Quickstart¶
@Composable
fun WhereAmI() {
val tracker = rememberLocationTracker()
val scope = rememberCoroutineScope()
var label by remember { mutableStateOf("Tap to find me") }
Button(onClick = {
scope.launch {
label = runCatching { tracker.getCurrentLocation() }
.map { "${it.latitude}, ${it.longitude}" }
.getOrElse { e -> "Couldn't locate: ${e.message}" }
}
}) {
Text(label)
}
}
Quickstart guide walks through manifests, permissions, and the streaming API.
Pairs well with¶
- Aagya for the permission flow. The two libraries are intentionally decoupled but share design philosophy.
Why "Dhruva"?¶
Dhruva (ध्रुव) is the polestar in Indian astronomy. Mariners used it as a fixed reference to find their way home. The name suits a library whose job is to tell you where you are.