Is there someone who knows, how to calculate the bearing from my own location to another location?
I have tried it with an old sub out of basic4ppc, but it doesn't work...
Thanks for help....
I have tried it with an old sub out of basic4ppc, but it doesn't work...
B4X:
sub Kursberechnung (Lat1,Lon1,Lat2,Lon2 As Double) As Double
Dim tc1, sn, d, Kurs As Double
'Umrechnung der Koordinaten von Grad in Bogemmaß'
Lat1 = Lat1 * cPI / 180
Lon1 = -Lon1 * cPI / 180
Lat2 = Lat2 * cPI / 180
Lon2 = -Lon2 * cPI / 180
'Formel zur Berechnung der Distanz zwischen der aktuellen Position und dem Ziel'
d = 2 * ASin(Sqrt((Sin((lat1-lat2)/2))^2 + Cos(lat1)*Cos(lat2)*(Sin((lon1-lon2)/2))^2))
'Formel zur Berechnung des Kurses vom aktuellen Standpunkt zum Ziel in Anhängigkeit vom Norden in Bogenmaß'
If Cos(Lat1) < 1e-7 Then
If (Lat1 > 0) Then
tc1 = cPI
Else
tc1= 2*cPI
End If
Else
sn = Sin(Lon2-Lon1)
If Abs(sn) < 1e-7 Then
If Lat1 > Lat2 Then tc1 = cPI Else tc1 = 2*cPI
Else If sn < 0 Then
tc1=ACos((Sin(Lat2)-Sin(Lat1)*Cos(d))/(Sin(d)*Cos(Lat1)))
Else
tc1=2*cPI-ACos((Sin(Lat2)-Sin(Lat1)*Cos(d))/(Sin(d)*Cos(Lat1)))
End If
End If
'Rückrechnung des Kurses von Bogenmaß in °'
Kurs = tc1 * 180 / cPI
Return Kurs
End Sub
Thanks for help....