feat: sort by location
This commit is contained in:
@@ -66,3 +66,20 @@ export function timeToMins(time: string) {
|
||||
const [hour, min] = time.split(":");
|
||||
return Number(hour) * 60 + Number(min);
|
||||
}
|
||||
|
||||
export function haversineDistance(
|
||||
lat1Deg: number,
|
||||
lng1Deg: number,
|
||||
lat2Deg: number,
|
||||
lng2Deg: number,
|
||||
radius: number = 6371e3
|
||||
): number {
|
||||
const lat1 = lat1Deg * (Math.PI / 180);
|
||||
const lat2 = lat2Deg * (Math.PI / 180);
|
||||
const deltaLat = (lat2Deg - lat1Deg) * (Math.PI / 180);
|
||||
const deltaLng = (lng2Deg - lng1Deg) * (Math.PI / 180);
|
||||
const e1 =
|
||||
Math.pow(Math.sin(deltaLat / 2), 2) +
|
||||
Math.pow(Math.sin(deltaLng / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
|
||||
return radius * 2 * Math.asin(Math.sqrt(e1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user