I've been using the following code to determine distance between two lat long cooridinates.
Wish I could take credit for it...but I can't...although, I do not remember what site I got it from. This is by far the best one I've found, as it takes into account great circle routings for determining the distance.
I have also defined the following Constants:
This will return your distance value in Nautical Miles.
I'm wondering if anyone has any advice on how to modify this function to also obtain an initial course. I have done it, but the course I come up with, doesn't apply the great circle method... I think if I new what side of the triangle the A, B, and C above represented, I could figure it out....however, my small amount of trig knowledge has escaped my mind as of late, just hoping maybe someone can help out a little bit.
Thanks!
Code:
Function CalculateDistance(lat1, lon1, lat2, lon2) As Double
Dim A As Double
Dim B As Double
Dim C As Double
Dim X As Double
A = Cos(lat1 * PI / 180) * Cos(lat2 * PI / 180) * Cos(lon1 * PI / 180) * Cos(lon2 * PI / 180)
B = Cos(lat1 * PI / 180) * Sin(lon1 * PI / 180) * Cos(lat2 * PI / 180) * Sin(lon2 * PI / 180)
C = Sin(lat1 * PI / 180) * Sin(lat2 * PI / 180)
If (A + B + C) >= 1 Or (A + B + C) <= -1 Then
CalculateDistance = 0
Else
X = (A + B + C)
CalculateDistance = (Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)) * RadiusEarth
End If
End Function
Wish I could take credit for it...but I can't...although, I do not remember what site I got it from. This is by far the best one I've found, as it takes into account great circle routings for determining the distance.
I have also defined the following Constants:
Code:
Public Const PI = 3.14159265358979
Public Const RadiusEarth = 3437.74677 ' Nautical Miles
Public Const CircumEarth = (RadiusEarth * 2 * PI)
Public Const NMPerDegreeLat = CircumEarth / 360
This will return your distance value in Nautical Miles.
I'm wondering if anyone has any advice on how to modify this function to also obtain an initial course. I have done it, but the course I come up with, doesn't apply the great circle method... I think if I new what side of the triangle the A, B, and C above represented, I could figure it out....however, my small amount of trig knowledge has escaped my mind as of late, just hoping maybe someone can help out a little bit.
Thanks!