WIP show POI list on click, save to RS
This commit is contained in:
14
app/utils/geo.js
Normal file
14
app/utils/geo.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export function getDistance(lat1, lon1, lat2, lon2) {
|
||||
const R = 6371e3; // metres
|
||||
const φ1 = (lat1 * Math.PI) / 180; // φ, λ in radians
|
||||
const φ2 = (lat2 * Math.PI) / 180;
|
||||
const Δφ = ((lat2 - lat1) * Math.PI) / 180;
|
||||
const Δλ = ((lon2 - lon1) * Math.PI) / 180;
|
||||
|
||||
const a =
|
||||
Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
|
||||
Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
|
||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
|
||||
return R * c; // in metres
|
||||
}
|
||||
Reference in New Issue
Block a user