mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-12 06:12:18 +00:00
refactor: extract place-search and routing provider modules
This commit is contained in:
1 parent
bdfd02ba93
commit
2793d7a8df
12 files changed
+709
-504
No files matched your search
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Haversine great-circle distance between two WGS-84 points.
|
||||
*
|
||||
* @param {number} lat1 - Latitude of point A (degrees).
|
||||
* @param {number} lon1 - Longitude of point A (degrees).
|
||||
* @param {number} lat2 - Latitude of point B (degrees).
|
||||
* @param {number} lon2 - Longitude of point B (degrees).
|
||||
* @returns {number} Distance in kilometers.
|
||||
*/
|
||||
export function haversineKm(lat1, lon1, lat2, lon2) {
|
||||
const toRad = (value) => value * Math.PI / 180;
|
||||
const dLat = toRad(lat2 - lat1);
|
||||
const dLon = toRad(lon2 - lon1);
|
||||
const a = Math.sin(dLat / 2) ** 2
|
||||
+ Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2;
|
||||
return 6371 * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
}
|
||||
Reference in new issue
Block a user