mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-13 16:07:30 +00:00
Add distance column for spots
This commit is contained in:
@@ -20,6 +20,20 @@ function calcBearing(lat1, lon1, lat2, lon2) {
|
||||
return bearing;
|
||||
}
|
||||
|
||||
function calcDistanceKm(lat1, lon1, lat2, lon2) {
|
||||
const EARTH_RADIUS_KM = 6371;
|
||||
lat1 *= Math.PI / 180;
|
||||
lon1 *= Math.PI / 180;
|
||||
lat2 *= Math.PI / 180;
|
||||
lon2 *= Math.PI / 180;
|
||||
const latDelta = lat2 - lat1;
|
||||
const lonDelta = lon2 - lon1;
|
||||
const a = Math.sin(latDelta / 2) ** 2 +
|
||||
Math.cos(lat1) * Math.cos(lat2) * Math.sin(lonDelta / 2) ** 2;
|
||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
return EARTH_RADIUS_KM * c;
|
||||
}
|
||||
|
||||
// Convert a Maidenhead grid reference of arbitrary precision to the lat/long of the centre point of the square.
|
||||
// Returns null if the grid format is invalid.
|
||||
function latLonForGridCentre(grid) {
|
||||
|
||||
Reference in New Issue
Block a user