UNPKG

514 BJavaScriptView Raw
1/** Calculates distance in km between two coordinates */
2export const distance = (pointA, pointB) => {
3 const p = 0.017453292519943295; // Math.PI / 180
4 const c = Math.cos;
5 const a = 0.5 -
6 c((pointB.latitude - pointA.latitude) * p) / 2 +
7 (c(pointA.latitude * p) *
8 c(pointB.latitude * p) *
9 (1 - c((pointB.longitude - pointA.longitude) * p))) /
10 2;
11 return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
12};
13//# sourceMappingURL=distance.js.map
\No newline at end of file