Module:Sandbox/Hellknowz/CoordDistance explained

local main =

function main.HaversineDistance(frame)

local lat1 = frame.args["lat1"] local lon1 = frame.args["lon1"] local lat2 = frame.args["lat2"] local lon2 = frame.args["lon2"] local radius = 6371 -- km

local dlat = math.rad(lat2-lat1) local dlon = math.rad(lon2-lon1) local a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.rad(lat1)) * math.cos(math.rad(lat2)) * math.sin(dlon/2) * math.sin(dlon/2) local c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) return radius * c

end

return main