app(service): use shared util via FQN — replace import of distanceMeters in LocationService

This commit is contained in:
2025-09-08 23:41:38 +02:00
parent 36c38bfd5f
commit 0003e74011
2 changed files with 9 additions and 9 deletions

View File

@@ -17,7 +17,7 @@ import app.klottr.net.NoteDTO
import app.klottr.util.FoundStore import app.klottr.util.FoundStore
import app.klottr.util.LastLocationStore import app.klottr.util.LastLocationStore
import app.klottr.util.SettingsStore import app.klottr.util.SettingsStore
import app.klottr.util.distanceMeters // import app.klottr.util.distanceMeters
import com.google.android.gms.location.LocationCallback import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationResult import com.google.android.gms.location.LocationResult
@@ -184,7 +184,7 @@ class LocationService : Service() {
} }
for (n in nearby) { for (n in nearby) {
val d = distanceMeters(lat, lon, n.a, n.o).roundToInt() val d = app.klottr.util.distanceMeters(lat, lon, n.a, n.o).roundToInt()
handleCandidate( handleCandidate(
layer = FoundStore.LAYER_KLOTTER, layer = FoundStore.LAYER_KLOTTER,
id = n.i.toString(), id = n.i.toString(),

View File

@@ -5,13 +5,13 @@ import app.klottr.data.NoteEntity
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlin.math.* import kotlin.math.*
fun distanceMeters(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double { //fun distanceMeters(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
val R = 6371000.0 // val R = 6371000.0
val dLat = Math.toRadians(lat2 - lat1) // val dLat = Math.toRadians(lat2 - lat1)
val dLon = Math.toRadians(lon2 - lon1) // val dLon = Math.toRadians(lon2 - lon1)
val a = sin(dLat/2).pow(2.0) + cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2)) * sin(dLon/2).pow(2.0) // val a = sin(dLat/2).pow(2.0) + cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2)) * sin(dLon/2).pow(2.0)
return 2 * R * atan2(sqrt(a), sqrt(1 - a)) // return 2 * R * atan2(sqrt(a), sqrt(1 - a))
} //}
fun roundCoord(v: Double): Double = (v * 1e5).roundToInt() / 1e5 fun roundCoord(v: Double): Double = (v * 1e5).roundToInt() / 1e5