in packages/@fbcmobile-ui/Utils/MapUtils.js [49:78]
export function _getHaversineDistanceBetweenLocations(
point1: ?Coords,
point2: ?Coords,
): ?number {
if (
point1 == null ||
point2 == null ||
point1.latitude == null ||
point1.longitude == null ||
point2.latitude == null ||
point2.longitude == null
) {
return null;
}
// Lat/Lng are given as degrees, so we convert to radians.
const lat1 = point1.latitude * DEGREES_TO_RADIANS;
const long1 = point1.longitude * DEGREES_TO_RADIANS;
const lat2 = point2.latitude * DEGREES_TO_RADIANS;
const long2 = point2.longitude * DEGREES_TO_RADIANS;
const latDiff = lat1 - lat2;
const lngDiff = long1 - long2;
const h =
_haversine(latDiff) + Math.cos(lat1) * Math.cos(lat2) * _haversine(lngDiff);
const distance = TWICE_EARTH_RADIUS * Math.asin(Math.sqrt(h));
return distance;
}