UNPKG

@mediarithmics/plugins-nodejs-sdk

Version:

This is the mediarithmics nodejs to help plugin developers bootstrapping their plugin without having to deal with most of the plugin boilerplate

22 lines 880 B
"use strict"; /** * Calculate the distance in Km * Sourced from StackOverflow (https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula) * This is the 'fastest' algorithm apparently * * @param lat1 * @param lon1 * @param lat2 * @param lon2 * @returns number The distance in km */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getDistanceFromLatLonInKm = void 0; const getDistanceFromLatLonInKm = (lat1, lon1, lat2, lon2) => { const p = 0.017453292519943295; // Math.PI / 180 const c = Math.cos; const a = 0.5 - c((lat2 - lat1) * p) / 2 + (c(lat1 * p) * c(lat2 * p) * (1 - c((lon2 - lon1) * p))) / 2; return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km }; exports.getDistanceFromLatLonInKm = getDistanceFromLatLonInKm; //# sourceMappingURL=GeolocHelpers.js.map