This commit is contained in:
lunaticbum 2024-10-10 11:11:35 +09:00
parent 96b26b8c37
commit d7f9c251a6

View File

@ -26,6 +26,7 @@ import java.math.RoundingMode
import java.util.Locale import java.util.Locale
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.math.cos
class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGetter(context, workerParams) { class LocationGetter(context: Context, workerParams: WorkerParameters) : BaseGetter(context, workerParams) {
companion object { 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)
} }