Add distance column for spots

This commit is contained in:
Ian Renton
2026-08-13 14:49:15 +01:00
parent d1a9af9932
commit 186f03a233
11 changed files with 69 additions and 19 deletions
+14
View File
@@ -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) {