Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import com.what3words.components.compose.maps.state.W3WMapState
import com.what3words.components.compose.maps.state.camera.W3WCameraState
import com.what3words.core.types.common.W3WError
import com.what3words.core.types.geometry.W3WCoordinates
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch

/**
* A composable function that displays a What3Words (W3W) map.
Expand Down Expand Up @@ -311,20 +314,21 @@ private fun fetchCurrentLocation(
mapManager: W3WMapManager,
onError: ((W3WError) -> Unit)? = null
) {
// Fetch location
locationSource?.fetchLocation(
onLocationFetched = { location ->
// Update camera state
mapManager.moveToPosition(
coordinates = W3WCoordinates(location.latitude, location.longitude),
animate = true
)
//TODO: Update button state
},
onError = { error ->
onError?.invoke(W3WError("Location fetch failed: ${error.message}"))
locationSource?.let {
CoroutineScope(IO).launch {
try {
val location = it.fetchLocation()
// Update camera state
mapManager.moveToPosition(
coordinates = W3WCoordinates(location.latitude, location.longitude),
animate = true
)
//TODO: Update button state
} catch (e: Exception) {
onError?.invoke(W3WError("Location fetch failed: ${e.message}"))
}
}
)
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.what3words.components.compose.maps.models

import android.location.Location
import kotlinx.coroutines.flow.StateFlow

interface W3WLocationSource {
fun fetchLocation(
onLocationFetched: (Location) -> Unit,
onError: (Exception) -> Unit,
)
// hasPermission && isLocationEnabled
val isActive: StateFlow<Boolean>

// Trigger fetch current location
suspend fun fetchLocation(): Location
}