local function sphericalDistanceBetween( point1, point2 )
local dLongitude = point2.longitude - point1.longitude
local dLatitude = point2.latitude - point1.latitude
local R = 6371 – Earth radius in kilometers
– Localize some math calls
local sin = math.sin
local cos = math.cos
local sqrt = math.sqrt
local atan2 = math.atan2
local a = ( sin( dLatitude/2 ) )^2 + cos( point1.y ) * cos( point2.y ) * ( sin( dLongitude/2 ) )^2
local c = 2 * atan2( sqrt( a ), sqrt( 1-a ) )
local d = R * c
return d * math.pi / 180
end