ChatGPT has this:
Code:
Const PI As Double = 3.14159265358979
Function GetBearingAngle(lat1 As Double, lon1 As Double, lat2 As Double, lon2 As Double) As Double
Dim radLat1 As Double, radLat2 As Double
Dim radLon1 As Double, radLon2 As Double
Dim deltaLon As Double
Dim y As Double, x As Double
Dim bearing As Double
' Convert degrees to radians
radLat1 = lat1 * PI / 180
radLat2 = lat2 * PI / 180
radLon1 = lon1 * PI / 180
radLon2 = lon2 * PI / 180
deltaLon = radLon2 - radLon1
y = Sin(deltaLon) * Cos(radLat2)
x = Cos(radLat1) * Sin(radLat2) - Sin(radLat1) * Cos(radLat2) * Cos(deltaLon)
bearing = Atn2(y, x) ' Custom function defined below
' Convert from radians to degrees
bearing = bearing * 180 / PI
' Normalize to 0-360
If bearing < 0 Then
bearing = bearing + 360
End If
GetBearingAngle = bearing
End Function
' VBA doesn't have Atn2, so we define it
Private Function Atn2(y As Double, x As Double) As Double
If x > 0 Then
Atn2 = Atn(y / x)
ElseIf x < 0 Then
Atn2 = Atn(y / x) + PI * Sgn(y)
ElseIf y <> 0 Then
Atn2 = PI / 2 * Sgn(y)
Else
Atn2 = 0 ' undefined, both x and y are 0
End If
End Function
using your sample coordinate in immediate window:
Code:
?GetBearingAngle(53.6304,9.9882,48.3538,11.7861)
the result: