Distance Formula

Public Shared Function Distance(ByVal lat1 As Double, ByVal lat2 As Double, ByVal lon1 As Double, ByVal lon2 As Double) As Double

Dim la1 As Double, la2 As Double, lo1 As Double, lo2 As Double

'Rad = 3.1415926535 / 180.0#
'Rad = 0.017453293

la1 = lat1 * 0.017453293
la2 = lat2 * 0.017453293
lo1 = lon1 * 0.017453293
lo2 = lon2 * 0.017453293

'la1 = lat1 * (Math.PI / 180.0#)
'la2 = lat2 * (Math.PI / 180.0#)
'lo1 = lon1 * (Math.PI / 180.0#)
'lo2 = lon2 * (Math.PI / 180.0#)

Distance = Math.Acos(Math.Sin(la1) * Math.Sin(la2) + Math.Cos(la1) * Math.Cos(la2) * Math.Cos(lo2 - lo1)) * 6371000.0#

End Function