Public Function DistanceKilometers(ByVal _lat1 As Double, ByVal _lon1 As Double, ByVal _lat2 As Double, ByVal _lon2 As Double) As Double
Const rad As Double = Math.PI / 180
Dim lon1 As Double = rad * -_lon1
Dim lat1 As Double = rad * _lat1
Dim lon2 As Double = rad * _lon2
Dim lat2 As Double = rad * _lat2
Dim d As Double = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin((lat1 - lat2) / 2), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin((lon1 - lon2) / 2), 2)))
Return CSng((1.852 * 60 * d / rad))
End Function
|