From d7f9c251a616fdb3f0d1767c6369b9254661ccf4 Mon Sep 17 00:00:00 2001 From: lunaticbum <> Date: Thu, 10 Oct 2024 11:11:35 +0900 Subject: [PATCH] ,.. --- .../lunar/launcher/workers/LocationGetter.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt b/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt index f39360e..b415942 100644 --- a/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt +++ b/app/src/main/kotlin/rasel/lunar/launcher/workers/LocationGetter.kt @@ -26,6 +26,7 @@ import java.math.RoundingMode import java.util.Locale import java.util.concurrent.Executors import java.util.concurrent.TimeUnit +import kotlin.math.cos class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGetter(context, workerParams) { companion object { @@ -114,4 +115,27 @@ class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGet } } +} + + +val EARTH_RADIUS_METERS = 6371000 +val LATITUDE_DEGREE_PER_METER: Double = 1.0 / (2 * Math.PI * EARTH_RADIUS_METERS / 360) + +fun latitudeRange(latitude: Double, radiusInMeters: Int): DoubleArray { + val degreeRange = radiusInMeters * LATITUDE_DEGREE_PER_METER + + val minLatitude = latitude - degreeRange + val maxLatitude = latitude + degreeRange + + return doubleArrayOf(minLatitude, maxLatitude) +} + +fun longitudeRange(latitude: Double, longitude: Double, radiusInMeters: Int): DoubleArray { + val longitudeDegreePerMeter: Double = 360 / (2 * Math.PI * EARTH_RADIUS_METERS * cos(Math.toRadians(latitude))) + val degreeRange = longitudeDegreePerMeter * radiusInMeters + + val minLongitude = longitude - degreeRange + val maxLongitude = longitude + degreeRange + + return doubleArrayOf(minLongitude, maxLongitude) } \ No newline at end of file