Reliable. Battery-Conscious. Native Performance.
Anchor is a native, Kotlin-first background geolocation library for Kotlin Multiplatform, designed for high performance and seamless integration in modern Android and iOS applications.
⚠️ Note: The product is currently in its final stages of development and testing. The official v1.0 release is expected during February 2026.
- 🔋 Always Background: Architected specifically for reliable, long-running background tracking.
- 🎯 Platform Tuned: Granular control over Android Priority/Interval and iOS Accuracy/Activity Type.
- 🚀 Modern API: Built with Kotlin DSL, Coroutines, and Flow.
- 📱 Cross-Platform: Single shared API for Android and iOS.
Add the dependency to your commonMain source set in build.gradle.kts:
commonMain.dependencies {
implementation("io.anchorkmp:core:0.0.1")
}🤖 Android Setup
No manual initialization code is required. However, you must declare the foreground service type in your manifest if you are targeting Android 14+.
The library automatically includes the following permissions:
ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATIONACCESS_BACKGROUND_LOCATIONFOREGROUND_SERVICE_LOCATIONPOST_NOTIFICATIONSACTIVITY_RECOGNITION
🍎 iOS Setup
Add the following keys to your Info.plist (typically in iosApp/iosApp/Info.plist):
<!-- Location Permissions -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to track your journey.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We need your location to track your journey even in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need your location to track your journey even in the background.</string>
<!-- Motion Permission (for Activity Recognition) -->
<key>NSMotionUsageDescription</key>
<string>We need access to motion data to detect if you are walking, running, or driving.</string>
<!-- Background Modes -->
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>fetch</string>
<string>processing</string>
</array>Initialize Anchor in your application startup logic.
import io.anchorkmp.core.*
import kotlin.time.Duration.Companion.seconds
Anchor.init {
// Shared Options
trackActivity = true // Enable activity recognition (walking, driving, etc.)
minUpdateDistanceMeters = 10.0 // Minimum distance before an update is triggered
// Android Specifics
android {
updateInterval = 10.seconds // Desired frequency of updates
priority = AndroidPriority.BALANCED // Balance between battery and accuracy
notification {
title = "Tracking Active" // Persistent notification title
body = "Location tracking is on" // Persistent notification body
iconName = "ic_tracker" // Drawable resource name
}
}
// iOS Specifics
ios {
desiredAccuracy = IosAccuracy.BEST // kCLLocationAccuracyBest
autoPause = true // Allow system to pause updates to save battery
activityType = IosActivityType.OTHER // CLActivityType
displayBackgroundLocationIndicator = true // Show blue pill in status bar
}
}Anchor provides a simple coroutine-based API for permission management.
scope.launch {
// 1. Request permissions (suspends until user decides)
// Suggest asking for Notifications & Motion first
Anchor.requestPermission(PermissionScope.NOTIFICATIONS)
Anchor.requestPermission(PermissionScope.MOTION)
// 2. Request Background Location
val status = Anchor.requestPermission(PermissionScope.BACKGROUND)
if (status == PermissionStatus.GRANTED) {
// 3. Start Tracking
Anchor.startTracking()
} else {
println("Permission denied")
}
}scope.launch {
Anchor.locationFlow.collect { location ->
println("📍 Location: ${location.latitude}, ${location.longitude}")
println("🏃 Activity: ${location.activity}")
}
}💡 Pro Tip: For robust background tracking that survives process death, initialize Anchor and subscribe to updates in your
Applicationclass, not your Activity/UI. See Best Practices.
Check out the sample/ directory for a complete Compose Multiplatform app demonstrating background tracking and native maps.
- Create
local.propertiesin the project root. - Add your Google Maps API Key:
MAPS_API_KEY=AIzaSy... - Run:
./gradlew :sample:composeApp:installDebug
- Open
sample/iosApp/iosApp.xcodeprojin Xcode. - Select your target device and run. (Uses native Apple Maps, no key required).
Licensed under Apache 2.0.
Built with ❤️ by Livotov Labs.