
One-shot and continuous location tracking with configurable timeouts and intervals, lifecycle-aware updates, typed error returns, battery-optimized defaults, and UI-friendly factory.
ध्रुव, the polestar. The unmoving guide that helps you find where you are.
A small Kotlin Multiplatform location library for Android and iOS. One-shot and continuous tracking, with the right defaults baked in.
Location code looks the same in every Android codebase: import FusedLocationProviderClient,
write a LocationCallback, deal with foreground / background lifecycle, marshal to a
Flow. On iOS it's CLLocationManager, a CLLocationManagerDelegate, lifecycle
hooks. None of it is hard, but all of it is paperwork.
Dhruva is the paperwork:
LocationTracker interface with getCurrentLocation() and startTracking().FusedLocationProviderClient (battery-optimized, the
Google-blessed default).CLLocationManager, with a delegate that already does the
bridging dance.LocationErrors; nothing throws across the bridge.Flow<Location>. Updates respect interval and
distance config. Cancel the flow to stop tracking.LocationErrors.rememberLocationTracker() for Compose; plain interface
for non-Compose code.@Composable
fun WhereAmI() {
val tracker = rememberLocationTracker()
var label by remember { mutableStateOf("Tap to find me") }
val scope = rememberCoroutineScope()
Button(onClick = {
scope.launch {
label = runCatching { tracker.getCurrentLocation() }
.map { "${it.latitude}, ${it.longitude}" }
.getOrElse { e -> "Couldn't locate: ${e.message}" }
}
}) {
Text(label)
}
}Continuous tracking:
LaunchedEffect(Unit) {
tracker.startTracking(LocationConfig(updateIntervalMs = 5_000))
.collect { location ->
map.center(location)
}
}| Artifact | Purpose | Required? |
|---|---|---|
io.github.ksharma-xyz:dhruva-state |
Location, LocationConfig, LocationPriority, LocationError. |
yes |
io.github.ksharma-xyz:dhruva-data |
LocationTracker interface and Android/iOS implementations. |
yes |
io.github.ksharma-xyz:dhruva-di-koin |
Optional Koin module factory. | optional |
FusedLocationProviderClient,
so the host app must include Google Play Services.CLLocationManager directly, no extra dependencies.dhruva-geocoding module.LocationManager directly, for FOSS distribution.See CONTRIBUTING.md. PRs welcome.
Dhruva is named for ध्रुव, the polestar in Indian astronomy, traditionally the fixed point that mariners used to find their way home.
ध्रुव, the polestar. The unmoving guide that helps you find where you are.
A small Kotlin Multiplatform location library for Android and iOS. One-shot and continuous tracking, with the right defaults baked in.
Location code looks the same in every Android codebase: import FusedLocationProviderClient,
write a LocationCallback, deal with foreground / background lifecycle, marshal to a
Flow. On iOS it's CLLocationManager, a CLLocationManagerDelegate, lifecycle
hooks. None of it is hard, but all of it is paperwork.
Dhruva is the paperwork:
LocationTracker interface with getCurrentLocation() and startTracking().FusedLocationProviderClient (battery-optimized, the
Google-blessed default).CLLocationManager, with a delegate that already does the
bridging dance.LocationErrors; nothing throws across the bridge.Flow<Location>. Updates respect interval and
distance config. Cancel the flow to stop tracking.LocationErrors.rememberLocationTracker() for Compose; plain interface
for non-Compose code.@Composable
fun WhereAmI() {
val tracker = rememberLocationTracker()
var label by remember { mutableStateOf("Tap to find me") }
val scope = rememberCoroutineScope()
Button(onClick = {
scope.launch {
label = runCatching { tracker.getCurrentLocation() }
.map { "${it.latitude}, ${it.longitude}" }
.getOrElse { e -> "Couldn't locate: ${e.message}" }
}
}) {
Text(label)
}
}Continuous tracking:
LaunchedEffect(Unit) {
tracker.startTracking(LocationConfig(updateIntervalMs = 5_000))
.collect { location ->
map.center(location)
}
}| Artifact | Purpose | Required? |
|---|---|---|
io.github.ksharma-xyz:dhruva-state |
Location, LocationConfig, LocationPriority, LocationError. |
yes |
io.github.ksharma-xyz:dhruva-data |
LocationTracker interface and Android/iOS implementations. |
yes |
io.github.ksharma-xyz:dhruva-di-koin |
Optional Koin module factory. | optional |
FusedLocationProviderClient,
so the host app must include Google Play Services.CLLocationManager directly, no extra dependencies.dhruva-geocoding module.LocationManager directly, for FOSS distribution.See CONTRIBUTING.md. PRs welcome.
Dhruva is named for ध्रुव, the polestar in Indian astronomy, traditionally the fixed point that mariners used to find their way home.