Haversine Distance
Calculates the distance on a sphere between two points given in latitude and longitude using the haversine formula.
The haversine formula can be found on Wikipedia
The Haversine Distance is implemented as a function as a class would be kind of overkill.
haversineDinstance(la1: Double, lo1: Double, la2: Double, lo2: Double, radius: Double = 6367444.7) -> Double
la1is the latitude of point 1 in degrees.lo1is the longitude of point 1 in degrees.la2is the latitude of point 2 in degrees.lo2is the longitude of point 2 in degrees.radiusis the radius of the sphere considered in meters, which defaults to the mean radius of the earth (from WolframAlpha).
The function contains 3 closures in order to make the code more readable and comparable to the Haversine formula given by the Wikipedia page mentioned above.
haversineimplements the haversine, a trigonometric function.ahaversinethe inverse function of the haversine.dToRa closure converting degrees to radians.
The result of haversineDistance is returned in meters.
Written for Swift Algorithm Club by Jaap Wijnen.