Khudoyshukur Juraev
01/22/2024, 6:55 AMDrivers {
id: Long
......
}
DriverLocations {
id: Long
driverId: Long
latitude: Double
longitude: Double
datetime: Long
}
I need to query the drivers within 1 km radius from Some point.
To calculate distance, i can use:
fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
val earthRadius = 6371000 // Radius of the earth in meters
val latDistance = Math.toRadians(lat2 - lat1)
val lonDistance = Math.toRadians(lon2 - lon1)
val a = sin(latDistance / 2) * sin(latDistance / 2) +
cos(Math.toRadians(lat1)) * cos(Math.toRadians(lat2)) *
sin(lonDistance / 2) * sin(lonDistance / 2)
val c = 2 * atan2(sqrt(a), sqrt(1 - a))
return earthRadius * c // Calculate the distance in meters
}
However, i do not now how to query this with exposed?hfhbd
01/22/2024, 6:59 AMChristopher Hübner
01/22/2024, 12:21 PMKhudoyshukur Juraev
01/22/2024, 2:11 PM