in packages/geofire-common/src/index.ts [370:385]
export function distanceBetween(location1: Geopoint, location2: Geopoint): number {
validateLocation(location1);
validateLocation(location2);
const radius = 6371; // Earth's radius in kilometers
const latDelta = degreesToRadians(location2[0] - location1[0]);
const lonDelta = degreesToRadians(location2[1] - location1[1]);
const a = (Math.sin(latDelta / 2) * Math.sin(latDelta / 2)) +
(Math.cos(degreesToRadians(location1[0])) * Math.cos(degreesToRadians(location2[0])) *
Math.sin(lonDelta / 2) * Math.sin(lonDelta / 2));
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return radius * c;
}