Jump to content
The simFlight Network Forums

HowTo - Finding in what airport the aircraft is


Recommended Posts

Hello all.

As I dig around trying to make my small app work (it will, someday), I'll try to share some VB2008 code snippets so others can use, in case they need it.

The next subroutine will set the "arpt" global variable to the current airport's ICAO.

Recipe:

- You need a text file with all the airports, formatted like this:

(...)

EDDF;50.026422;8.543125

LPPT;38.781311;-9.135919

LPFR;37.014425;-7.965911

(...)

Maybe you can start with the one provided here (verify if the usage license allows you to use it in your app !)

Code:

You'll need:

Imports System.IO

In the form declarations (so it is globally available):

Dim arpt As String = ""

The subroutine itself (I didn't pay attention to the var types, so everyting is "double"feel free to correct my code !):

Sub mylocation(ByVal curlat As Double, ByVal curlon As Double)

Dim path As String = "path\to\your\textfile.txt"

Dim latdif As Double = 10000

Dim londif As Double = 10000

Dim sr As StreamReader = File.OpenText(path)

Do While sr.Peek()

Dim somatemp As Double = 0

Dim Alat As Double

Dim Blon As Double

Dim temp As String = sr.ReadLine()

Dim TestArray() As String = Split(temp, ";")

If TestArray(0) = "" Then Exit Do 'to avoid 'bogus' end-of-file...

Alat = Val(TestArray(1))

Blon = Val(TestArray(2))

If (Math.Abs(Alat - curlat) < latdif) And (Math.Abs(Blon - curlon) < londif) Then

latdif = Math.Abs(Alat - curlat)

londif = Math.Abs(Blon - curlon)

arpt = TestArray(0)

End If

Loop

sr.Close()

End Sub

Now, everytime you want to know in what airport your aircraft is, just call the subroutine like this:

mylocation(lat,lon)

using offsets 0x6010 for the latitude value and 0x6018 for the longitude one, and your "arpt" variable should reflect the current airport ICAO.

Feel free to correct my code (it's not pretty, but it's working for me ! ) and to share your own code snippets :-)

For instance, I'm looking for a "total payload weight calculator" subroutine for VB2008... ;-)

"V"

Link to comment
Share on other sites

As I dig around trying to make my small app work (it will, someday), I'll try to share some VB2008 code snippets so others can use, in case they need it.

Thanks for your contributions.

Have you yet looked at the Lua program plug-in facilities in the latest interim updates for FSUIPC4 (see the FSX Downloads Announcement)? I know they are currently only for FSX, but I am really waiting for some feedback to see if it would be worth adding the same to FSUIPC3. So far it looks not, in fact. :-(

Little apps like idenfifying the nearest or current airport by ICAO seem very suitable for a Lua implementation, and the language isn't hard I think. FSUIPC4 runs any such plug-ins multithreaded in FSX's own process, with virtually no measurable impact on a 2- or 4-core system.

Best Regards

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.