[Quote Wikipedia: https://en.wikipedia.org/wiki/Haversine_formula]
"The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of haversines, that relates the sides and angles of spherical triangles."
The GUI uses two Airport UserControls, which each contain three ComboBoxes, and three Labels. The individual ComboBoxes are used to choose Country, City, and Airport. The UserControls expose Decimal latitude and longitude values through two Functions, named lat and lon.
To keep the application simple, a Form level DataTable is used, which is filled with data from a My.Resources Text File. In the creation of the UserControls, the DataTable is passed into the UserControl Constructor, so that filtered views from the table can be used in populating the ComboBoxes used for choosing departure and arrival airports.
To use the application, you'd first need to select a departure airport and an arrival airport, then simply clicking the command Button invokes the calculation code and the result is displayed in a Label.
The table is populated from data stored in a My.Resources Text file...
Dim
dt
As
New
DataTable
Private
Sub
Form1_Load(
ByVal
sender
System.
Object,
e
System.EventArgs)
Handles
MyBase.Load
lines()
String
= My.Resources.airports.Split(
String() {Environment.NewLine}, StringSplitOptions.None)
dt.Columns.Add(
"Country")
"City")
"Airport")
"IATA")
"lat",
GetType(
Decimal))
"lon",
For
Each
l
In
lines
dt.Rows.Add(l.Split(
","c)(3), l.Split(
","c)(2).Replace(
" - ",
", "), l.Split(
","c)(1), l.Split(
","c)(4),
CDec(l.Split(
","c)(6)),
","c)(7)))
Next
End
The UserControls are the means of selecting Airports, and also provide latitude and longitude coordinates for the selected Airports...
The entire DataTable is passed to each UserControl in its constructor. Filtered views are used as datasources for the three ComboBoxes.
There is one simple custom Event, which is raised when a new Airport is selected.
Public
Class
Airport
Event
Changed(
Object
,
(
title
DataTable)
InitializeComponent()
Label3.Text = title
Me
.dt = dt
dv
DataView(dt,
""
"Country ASC"
, DataViewRowState.CurrentRows)
ComboBox1.DataSource = dv.ToTable(
True
"Country"
)
ComboBox1.DisplayMember =
ComboBox1.SelectedIndex = -1
ComboBox1.SelectedIndex = 0
ComboBox1_SelectedIndexChanged(
ComboBox1.SelectedIndexChanged
"Country = '"
& ComboBox1.Text &
"'"
"City ASC"
ComboBox2.DataSource = dv.ToTable(
"City"
ComboBox2.DisplayMember =
ComboBox2_SelectedIndexChanged(
ComboBox2.SelectedIndexChanged
"City = '"
& ComboBox2.Text &
"Airport ASC"
ComboBox3.DataSource = dv
ComboBox3.DisplayMember =
"Airport"
Label2.DataBindings.Clear()
Label2.DataBindings.Add(
"Text"
, dv,
"IATA"
Function
lat()
Decimal
drv
DataRowView = TryCast(ComboBox3.SelectedItem, DataRowView)
If
Not
Is
Nothing
Then
Return
CDec
(drv.Item(
"lat"
))
Else
lon()
"lon"
Label2_TextChanged(
Label2.TextChanged
RaiseEvent
EventArgs)
Download on MSDN (VB2008)