Configuration

AnchorKMP is highly configurable to suit different use cases, from high-precision navigation to battery-saving passive tracking. Configuration is handled via the AnchorConfig class.

Creating a Configuration

You create a configuration object using the Anchor.init DSL. This allows you to set common options and platform-specific overrides.

Kotlin
Anchor.init {
    // Common Settings
    minUpdateDistanceMeters = 10.0 // Minimum distance between updates
    trackActivity = true           // Enable activity recognition (still/walking/etc)

    // Android Specifics
    android {
        updateInterval = 5.seconds
        priority = AndroidPriority.HIGH_ACCURACY
        
        // Customize the Foreground Service Notification
        notification {
            title = "Tracking Trip"
            body = "We are recording your location"
            iconName = "my_custom_icon" // Drawable resource name
            channelName = "My App Location"
        }
    }

    // iOS Specifics
    ios {
        desiredAccuracy = IosAccuracy.BEST
        activityType = IosActivityType.FITNESS
        autoPause = false
        displayBackgroundLocationIndicator = true
    }
}

Common Settings

Property
Type
Description
Default

minUpdateDistanceMeters

Double

The minimum distance (in meters) the device must move before a location update is generated.

0.0

trackActivity

Boolean

If true, attempts to detect user activity (Walking, Driving, etc.) attached to the location update.

false

Android Configuration

Configured inside the android { ... } block.

Property
Type
Description
Default

updateInterval

Duration

The desired interval for active location updates.

10.seconds

priority

AndroidPriority

The priority/accuracy hint for the Fused Location Provider.

BALANCED

notification

AnchorNotification

Configuration for the foreground service notification.

(Default impl)

Android Priority Levels

chevron-rightShow Android priority levelshashtag
  • HIGH_ACCURACY: Request the most accurate locations available. Used for mapping/navigation.

  • BALANCED: Block level accuracy (approx 100m). Good for city-level tracking.

  • LOW_POWER: City level accuracy (approx 10km).

  • PASSIVE: Passively receives locations generated by other apps.

Notification Customization

circle-info

For background tracking on Android, a Foreground Service is required. This service must display a persistent notification. You can customize:

  • title

  • body

  • iconName (Name of the drawable resource in androidMain/res/drawable)

  • channelId & channelName (For Android notification settings)

iOS Configuration

Configured inside the ios { ... } block.

Property
Type
Description
Default

desiredAccuracy

IosAccuracy

The desired accuracy level for the location manager.

BEST

activityType

IosActivityType

The type of activity for the system to optimize battery usage.

OTHER

autoPause

Boolean

Allow the system to pause updates automatically to save battery.

true

displayBackgroundLocationIndicator

Boolean

Show the blue pill/bar when tracking in background.

true

iOS Accuracy Levels

chevron-rightShow iOS accuracy levelshashtag
  • NAVIGATION: Highest possible accuracy.

  • BEST: Accurate to within a few meters.

  • NEAREST_TEN_METERS

  • HUNDRED_METERS

  • KILOMETER

  • THREE_KILOMETERS

iOS Activity Types

chevron-rightShow iOS activity typeshashtag
  • OTHER: Default.

  • AUTOMOTIVE_NAVIGATION: For vehicular navigation.

  • FITNESS: For pedestrian activities (running/walking).

  • OTHER_NAVIGATION: For other forms of navigation (boat, train, plane).

  • AIRBORNE: Strictly for airborne activities.