Hello Paul,
this is my current code
Public Function getgate(ByVal icaocode As String) As String
Using MyReader As New FileIO.TextFieldParser(Form1.fullFSpath.Value & "g5.csv")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim gatename As String
Dim gatenumber As String
Dim gatereturn As String
Dim currentRow As String()
Dim smallestDifference As Double = 0
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
If currentRow(0) = icaocode Then
gatename = currentRow(1)
gatenumber = currentRow(2)
Dim aaa As String = currentRow(3)
Dim bbb As String = currentRow(4)
Dim aaaa As Double = Double.Parse(aaa, CultureInfo.InvariantCulture)
Dim bbbb As Double = Double.Parse(bbb, CultureInfo.InvariantCulture)
Dim distance As Double = Form1.distance(Functions.getAircraftLatFS(), Functions.getAircraftLonFS(), aaaa, bbbb, "M")
If distance = smallestDifference Then
smallestDifference = distance
gatereturn = "" + gatename + " " + gatenumber + ""
Return gatereturn
MyReader.Close()
MyReader.Dispose()
Exit Function
End If
End If
Catch ex As FileIO.MalformedLineException
'MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
MyReader.Close()
MyReader.Dispose()
End Using
Return ""
End Function
I am in LPPT on gate 104, if the distance result is 0 it show gate 104.
if i change distance = to distance <= no result show
if i change smallDiference to 20 and keep <= it will show gate 105 but i'm on 104. (105 is near but is on my left side)
the distance function i have is
'M' is statute miles (default)
'K' is kilometers
'N' is nautical miles
Public Function distance(ByVal lat1 As Double, ByVal lon1 As Double,
ByVal lat2 As Double, ByVal lon2 As Double,
Optional ByVal unit As Char = "M"c) As Double
Dim theta As Double = lon1 - lon2
Dim dist As Double = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) +
Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) *
Math.Cos(deg2rad(theta))
dist = Math.Acos(dist)
dist = rad2deg(dist)
dist = dist * 60 * 1.1515
If unit = "K" Then
dist = dist * 1.609344
ElseIf unit = "N" Then
dist = dist * 0.8684
End If
Return dist
End Function
Thank you for your help