or even if you don't, because that library should be bulletproof.if you already use the GPS library
'It's looks about right on Google maps from the 2 points that I used.
Dim r As Int = 6371 '6371000
Dim lat1 As Double = 52.419242
Dim lon1 As Double = -1.770847
Dim x1 As Double = r * Cos(lat1) * Cos(lon1)
Dim y1 As Double = r * Sin(lat1) * Cos(lon1)
Dim lat2 As Double = 52.539881
Dim lon2 As Double = -1.898292
Dim x2 As Double = r * Cos(lat2) * Cos(lon2)
Dim y2 As Double = r * Sin(lat2) * Cos(lon2)
Dim Angle As Double = ATan2(y2 - y1, x2 - x1) * 180 / cPI
If Angle < 0 Then Angle = 360 + Angle
Log($"Angle (points 1 to 2) is at ${NumberFormat(Angle, 1, 2)}°"$)
With 2 points you can't calculate an angle. You need two lines. So at least you need a 3rd point (e.g. heading) which gives you a base line to calc the angle.
Here we speak of bearing, an angle on the compass, which is defined by two locations.With 2 points you can't calculate an angle.
Sub MainStartTest
Dim lat1 As Double = 52.419242
Dim lon1 As Double = -1.770847
Dim lat2 As Double = 52.539881
Dim lon2 As Double = -1.898292
Log(CourseFromLonLatDegrees(lat1, lon1, lat2, lon2))
End Sub
Sub CourseFromLonLatDegrees(Lat1 As Double, Lon1 As Double, Lat2 As Double, Lon2 As Double) As Double
Dim DegreesToRadians As Double = cPI / 180
Lat1 = Lat1 * DegreesToRadians
Lon1 = Lon1 * DegreesToRadians
Lat2 = Lat2 * DegreesToRadians
Lon2 = Lon2 * DegreesToRadians
Return CourseFromLonLatRadians(Lat1, Lon1, Lat2, Lon2) / DegreesToRadians
End Sub
Sub CourseFromLonLatRadians(Lat1 As Double, Lon1 As Double, Lat2 As Double, Lon2 As Double) As Double
Dim tc1 As Double
'formula from: https://edwilliams.org/avform.htm#Crs
If (Cos(Lat1) < 0.0000001) Then 'within one metre of north or south pole
If (Lat1 > 0) Then
tc1 = cPI 'starting from north pole, thus heading south
Else
tc1= 0 'starting from south pole, thus heading north
End If
Else
'Lon1 and Lon2 reversed in subtraction due to formula convention of west = +ve
tc1 = ATan2(Sin(Lon2 - Lon1) * Cos(Lat2), Cos(Lat1) * Sin(Lat2) - Sin(Lat1) * Cos(Lat2) * Cos(Lon2 - Lon1))
'translate to compass angle ie 0 = north, positive through E, S, W
If tc1 < 0 Then
tc1 = tc1 + 2 * cPI
End If
End If
Return tc1
End Sub
My interest was not in getting equations for the calculation, I already have some, but to see the original code and find where the error does come from.That's why I am interested to see the original code.