Skip to content

Feature Request: Background Location Tracking Support #250

@earlzdev

Description

@earlzdev

Feature Request: Background Location Tracking Support

Summary

The Compass KMM library currently supports only foreground location tracking. This feature request proposes adding support for background location updates, enabling apps to continue receiving location data when running in the background.

This capability is essential for use cases such as:

  • Fitness and activity tracking
  • Turn-by-turn navigation
  • Location-based reminders and geofencing

Without proper background support, these scenarios are limited or unreliable.


Proposed Implementation

1. iOS Support (LocationManagerDelegate.kt)

The current iOS implementation in:
compass-geolocation-mobile/src/iosMain/kotlin/dev/jordond/compass/geolocation/mobile/internal/LocationManagerDelegate.kt
lacks proper background configuration for CLLocationManager.

To enable background location tracking, the following properties should be set:

manager.allowsBackgroundLocationUpdates = true
manager.pausesLocationUpdatesAutomatically = false

These ensure:

  • The app continues receiving location updates in the background.
  • The system doesn't automatically pause updates when the app is idle.

⚠️ Note: iOS apps using this feature must declare "location" in UIBackgroundModes in the Info.plist.


2. Configuration API

To give developers explicit control, a flag for enabling background tracking should be added to the configuration.

Option A: Extend LocationRequest.kt

@Poko
public class LocationRequest(
    public val priority: Priority = Priority.Balanced,
    public val interval: Long = 5000L,
    public val maximumAge: Long = 0L,
    public val ignoreAvailableCheck: Boolean = false,
    public val enableBackgroundMode: Boolean = false, // NEW
)

Option B: Extend MobileLocator Factory

public fun MobileLocator(
    permissionController: LocationPermissionController = LocationPermissionController.mobile(),
    enableBackgroundTracking: Boolean = false, // NEW
): MobileLocator = createLocator(permissionController, enableBackgroundTracking)

The maintainers can decide which option better fits the library’s design. Option A offers fine-grained control per request; Option B keeps it simpler at the component level.


Offer to Contribute

I’d be happy to contribute this feature.

I have hands-on experience with:

  • iOS Core Location (including background modes)
  • Android location APIs and Foreground Services
  • Multiplatform library design (including KMM specifics)

I'd appreciate the maintainers' input on:

  1. Whether this feature aligns with project goals
  2. Preferred API design (Option A, B, or alternative)
  3. Breaking the implementation into reviewable steps or PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions