{"size": 761, "ext": "js", "max_stars_repo_path": "server/utils/Distance.js", "max_stars_repo_name": "iiTONELOC/proximo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/utils/Distance.js", "max_issues_repo_name": "iiTONELOC/proximo", "max_issues_repo_issues_event_min_datetime": "2021-07-17T15:52:53.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-02T14:23:35.000Z", "max_forks_repo_path": "server/utils/Distance.js", "max_forks_repo_name": "iiTONELOC/proximo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 33.0869565217, "max_line_length": 81, "alphanum_fraction": 0.5992115637}
const deg2rad = require('@stdlib/math-base-special-deg2rad');
const Distance = function (latitude1, longitude1, latitude2, longitude2, units) {
    const earthRadius = 6371; // Radius of the earth in km
    const dLat = deg2rad(latitude2 - latitude1);  // deg2rad below
    const dLon = deg2rad(longitude2 - longitude1);
    const a =
        (Math.sin(dLat / 2) * Math.sin(dLat / 2)) +
        (Math.cos(deg2rad(latitude1)) * Math.cos(deg2rad(latitude2))) *
        (Math.sin(dLon / 2) * Math.sin(dLon / 2))
        ;
    const c = 2 * (Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
    const d = earthRadius * c;
    const miles = d / 1.609344;

    if (units == 'km') {
        return d;
    } else {
        return miles;
    }
}

module.exports = Distance;
