app(service): use shared util via FQN — replace import of distanceMeters in LocationService
This commit is contained in:
@@ -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(),
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user