version
6.50
0
Form1
238
268
0
0
0
0
Sub designer
addform(Form1,"Form1","",220,220,220)@
addlabel(form1,Label4,155,30,55,25,"Deg",220,220,220,0,0,0,True,True,9)@
addlabel(form1,Label3,155,70,55,25,"KM",220,220,220,0,0,0,True,True,9)@
addlabel(form1,Label2,5,70,55,25,"Distance",220,220,220,0,0,0,True,True,9)@
addlabel(form1,Label1,35,30,30,25,"AZ",220,220,220,0,0,0,True,True,9)@
addtextbox(form1,TB2,70,70,75,22,"",255,255,255,0,0,0,True,True,False,9)@
addtextbox(form1,TB1,70,30,75,22,"",255,255,255,0,0,0,True,True,False,9)@
End Sub
@EndOfDesignText@
Sub Globals
gps_lat_rad = 0
gps_long_rad = 0
WP_lat_rad = 0
WP_long_rad = 0
distance = 0
L = 0
End Sub
Sub App_Start
Form1.Show
' get the gps reading, here replaced by numbers:
gps_lat = 30
gps_long = 30
wp_lat = 20
wp_long = 40
' define the coordinates of your present position from the GPS, in radians
gps_lat_rad = gps_lat * cPI / 180
gps_long_rad = gps_long * cPI / 180
' define the coordinates of the waypoint in radians
WP_lat_rad = wp_lat * cPI / 180
WP_long_rad = wp_long * cPI / 180
L = gps_long_rad - WP_long_rad
distance = calculate_distance
tb2.text = Format(distance * 111.111,"N1") ' in km
tb1.text = Format(calculate_bearing,"N1")
End Sub
Sub calculate_distance
D = (Sin(gps_lat_rad) * Sin(WP_lat_rad)) + (Cos(gps_lat_rad) * Cos(WP_lat_rad) * Cos(L ))
Return ACos(D)
End Sub
Sub calculate_bearing
C = (Sin(WP_lat_rad) - (Sin(gps_lat_rad) * Cos(distance))) / (Cos(gps_lat_rad) * Sin(distance))
If Sin(L) < 0 Then bearing = ACos(C) * 180/cPI Else bearing = (2*cPI - ACos(C)) * 180/cPI
' here I used the opposite definition of sinL to match the results.
Return bearing
End Sub
'WHERE:
'
'A = YOUR latitude in degrees.
'B = latitude of the other location in degrees.
'L = YOUR longitude minus that of the other location. (Algebraic difference.)
'D = Distance along path in degrees of arc.
'C = True bearing from north If the value For Sin(L) is positive. If
'Sin(L) is negative, True bearing is 360 - C.
'
'To convert degrees of arc To statute miles, multiply by 69.041.
'To convert degrees of arc To kilometers, multiply by 111.111.