Here's the formula for calculating the distance between one location to another. I may use this someday for an airport game I've always wanted to build.
function getDistance(lat1, lon1, lat2, lon2) { const R = 6371e3; // radius of Earth in meters const φ1 = toRadians(lat1); const φ2 = toRadians(lat2); const Δφ = toRadians(lat2 - lat1); const Δλ = toRadians(lon2 - lon1);
console.log(`Distance from ${london.name} to ${newYork.name}: ${londonToNewYork.toFixed(2)} kilometers`); console.log(`Distance from ${newYork.name} to ${tokyo.name}: ${newYorkToTokyo.toFixed(2)} kilometers`); console.log(`Distance from ${london.name} to ${tokyo.name}: ${londonToTokyo.toFixed(2)} kilometers`);