From 82c1b4490de366850614d9ce3cb06170ccb9f89e Mon Sep 17 00:00:00 2001 From: Ellen Poe Date: Fri, 3 Oct 2025 11:48:54 -0700 Subject: [PATCH] fix: if no location is available, use last known --- .../main/java/earth/maps/cardinal/data/LocationRepository.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cardinal-android/app/src/main/java/earth/maps/cardinal/data/LocationRepository.kt b/cardinal-android/app/src/main/java/earth/maps/cardinal/data/LocationRepository.kt index c82b577..16d4dd7 100644 --- a/cardinal-android/app/src/main/java/earth/maps/cardinal/data/LocationRepository.kt +++ b/cardinal-android/app/src/main/java/earth/maps/cardinal/data/LocationRepository.kt @@ -53,7 +53,7 @@ class LocationRepository @Inject constructor( private companion object { private const val LOCATION_REQUEST_INTERVAL_MS = 15000L // 15 seconds - private const val LOCATION_REQUEST_TIMEOUT_MS = 10000L // 10 seconds + private const val LOCATION_REQUEST_TIMEOUT_MS = 5000L // 5 seconds private const val CONTINUOUS_LOCATION_UPDATE_INTERVAL_MS = 5000L // 5 seconds private const val CONTINUOUS_LOCATION_UPDATE_DISTANCE_M = 5f // 5 meters private const val FUSED_PROVIDER_TIMEOUT_MS = @@ -458,13 +458,14 @@ class LocationRepository @Inject constructor( ) { kotlinx.coroutines.MainScope().launch { kotlinx.coroutines.delay(LOCATION_REQUEST_TIMEOUT_MS) + val lastKnownLocation = getLastKnownLocation(locationManager) if (locationDeferred.isActive) { try { locationManager.removeUpdates(locationListener) } catch (_: Exception) { // Ignore exceptions during cleanup } - locationDeferred.complete(null) + locationDeferred.complete(lastKnownLocation) } } } -- GitLab