Usage

Once you have setup the project and defined your configuration, you are ready to use AnchorKMP.

Initialization

You must initialize the Anchor singleton with your configuration before using any other features. This is typically done in your Application class or main entry point.

Kotlin
Anchor.init {
    // ... your configuration
}

Permissions

AnchorKMP provides a unified API to check and request permissions.

Checking Permissions

You can check the status of a specific permission scope non-blockingly:

Kotlin
val status = Anchor.checkPermission(PermissionScope.BACKGROUND)
if (status == PermissionStatus.GRANTED) {
    // Ready to track
}

Or check if the library is ready for the current configuration:

Kotlin
if (Anchor.isReady) {
    Anchor.startTracking()
}

Requesting Permissions

To request permissions, call requestPermission. This is a suspending function that handles the UI flow (launching a transparent Activity on Android, or system dialogs on iOS) and returns the result.

Permission Scopes

  • FOREGROUND: Access location while the app is in use.

  • BACKGROUND: Access location all the time.

  • NOTIFICATIONS: Permission to post notifications (Android).

  • MOTION: Activity Recognition / Motion usage.

Tracking Location

Continuous Updates

To receive continuous location updates, observe the locationFlow.

Start and stop the tracking engine:

Single Location

If you only need a one-time location fix:

Runtime Reconfiguration

You can update the configuration while the app is running (even while tracking). The engine will automatically restart or adjust to apply the new settings.