13 lines
518 B
JavaScript
13 lines
518 B
JavaScript
(function (ns) {
|
|
'use strict';
|
|
const radians = value => value * Math.PI / 180;
|
|
ns.Distance = {
|
|
meters(a, b) {
|
|
const dLat = radians(b.lat - a.lat); const dLon = radians(b.lon - a.lon);
|
|
const h = Math.sin(dLat / 2) ** 2 + Math.cos(radians(a.lat)) * Math.cos(radians(b.lat)) * Math.sin(dLon / 2) ** 2;
|
|
return 2 * 6371000 * Math.asin(Math.sqrt(h));
|
|
},
|
|
format(meters) { return meters < 1000 ? `${Math.round(meters)} m` : `${(meters / 1000).toFixed(1)} km`; }
|
|
};
|
|
}(window.Wegwichtel));
|