Skip to content

Commit a30fc5c

Browse files
authored
Enable background location updates on AppleLocationEngine (#166)
* fix: Enable background location updates * feat: Parameterize background location updates to avoid forcing users to use them * chore: Update version to v.5.0.0-pre7 and update changelog
1 parent 898d84a commit a30fc5c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Changelog for the MapLibre Navigation SDK for Android
33

44
MapLibre welcomes participation and contributions from everyone.
55

6+
### v5.0.0-pre7 - Jun 18, 2025
7+
8+
- Fix AppleLocationEngine by enabling background location updates [#166](https://github.com/maplibre/maplibre-navigation-android/pull/166)
9+
610
### v5.0.0-pre6 - Jun 13, 2025
711

812
- Fix crash on MapFpsDelegate, caused by null modifier [#141](https://github.com/maplibre/maplibre-navigation-android/issues/141)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.0-pre6
1+
5.0.0-pre7

maplibre-navigation-core/src/iosMain/kotlin/org/maplibre/navigation/core/location/engine/AppleLocationEngine.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ import platform.CoreLocation.CLLocation as AppleLocation
3030
* location. You can define a timeout for this request in the constructor.
3131
*
3232
* @param getLocationTimeout The maximum duration to wait for the one-time location request.
33+
* @param enableBackgroundLocationUpdates Enables CLLocationManager's background location updates.
3334
*/
34-
open class AppleLocationEngine(private val getLocationTimeout: Duration) :
35+
open class AppleLocationEngine(private val getLocationTimeout: Duration, private val enableBackgroundLocationUpdates: Boolean) :
3536
LocationEngine {
3637

37-
constructor() : this(getLocationTimeout = 5.seconds)
38+
constructor() : this(getLocationTimeout = 5.seconds, enableBackgroundLocationUpdates = true)
3839

3940
/**
4041
* A [MutableStateFlow] that holds the current location or null if no location was emitted yet.
@@ -50,6 +51,7 @@ open class AppleLocationEngine(private val getLocationTimeout: Duration) :
5051
* The underlying CLLocationManager instance used to fetch location updates.
5152
*/
5253
private val locationManager = CLLocationManager().also { locationManager ->
54+
locationManager.allowsBackgroundLocationUpdates = enableBackgroundLocationUpdates
5355
locationManager.delegate = locationDelegate
5456
}
5557

@@ -89,7 +91,9 @@ open class AppleLocationEngine(private val getLocationTimeout: Duration) :
8991
private suspend fun getLocation(timeout: Duration): Location? = withContext(Dispatchers.Main) {
9092
withTimeoutOrNull(timeout) {
9193
suspendCancellableCoroutine { continuation ->
92-
val locationManager = CLLocationManager()
94+
val locationManager = CLLocationManager().also {
95+
it.allowsBackgroundLocationUpdates = enableBackgroundLocationUpdates
96+
}
9397
locationManager.delegate = object : NSObject(), CLLocationManagerDelegateProtocol {
9498
/**
9599
* Called when the location manager updates the location.

0 commit comments

Comments
 (0)