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

23 lines (22 loc) 789 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 }); function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) { var p = 0.017453292519943295; // Math.PI / 180 var c = Math.cos; var 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;