Private Sub Application_Start (Nav As NavigationController)
.....
Dim Location1, Location2 As Location
Location1.Initialize2("50.289459", "6.791009")
Location2.Initialize2("51.346536", "6.343463")
Msgbox(Kursberechnung(Location1, Location2), "Kurs")
End Sub
Sub Kursberechnung(LocationAlt As Location, LocationNeu As Location) As Int
Dim d, tc1, sn As Double
Dim latAlt, lonAlt, latNeu, lonNeu As Double
'Umrechnung der Koordinaten von Grad In Bogemmaß'
'LatAlt und LonAlt Sind die alten Koordinaten, aus deren Sicht der Kurs bestimmt werden soll'
latAlt = LocationAlt.Latitude * cPI / 180
lonAlt = -LocationAlt.Longitude * cPI / 180
latNeu = LocationNeu.Latitude * cPI / 180
lonNeu = -LocationNeu.Longitude * cPI / 180
'Formel zur Berechnung der Distanz zwischen der alten und der neuen Position'
d = 2 * ASin(Sqrt(Power((Sin((latAlt-latNeu)/2)),2)+ Cos(latAlt)*Cos(latNeu)*Power((Sin((lonAlt-lonNeu)/2)),2)))
'Formel zur Berechnung des Kurses von der alten Position zur neuen Position in Abhängigkeit vom Norden In Bogenmaß'
If Cos(latAlt) < 1e-7 Then
If (latAlt > 0) Then
tc1 = cPI
Else
tc1= 2*cPI
End If
Else
sn = Sin(lonNeu-lonAlt)
If Abs(sn) < 1e-7 Then
If latAlt > latNeu Then tc1 = cPI Else tc1 = 2*cPI
Else If sn < 0 Then
tc1=ACos((Sin(latNeu)-Sin(latAlt)*Cos(d))/(Sin(d)*Cos(latAlt)))
Else
tc1=2*cPI-ACos((Sin(latNeu)-Sin(latAlt)*Cos(d))/(Sin(d)*Cos(latAlt)))
End If
End If
'Rückrechnung des Kurses von Bogenmaß in Grad'
Dim Kurs As Int
Kurs = NumberFormat(tc1 * 180 / cPI,1,0)
Return Kurs
End Sub