• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Detect current/nearest airport with simconnect?

Messages
33
Country
israel
I am trying to detect where the user has landed. I can’t find a good way to deduce that information, so I had to resort to subscribing to facilities and checking distance from each of the returned airports (40,000 calculations).

  1. Is there no better way?
  2. The documentation says that using SimConnect_SubscribeToFacilities_EX1 can return only the airports in the reality bubble (which is 200 nm). However, the managed code dll only exposes a “SubscribeToFacilities” method. Is there a way to get only the ones in the reality bubble?
simconnect.SubscribeToFacilities(SIMCONNECT_FACILITY_LIST_TYPE.AIRPORT, DATA_REQUESTS.AIRPORTS_REQUEST);

I see an old post about a db lookup in FSLog - the file cannot be downloaded, but it seems similar to my approach?

Thanks!
 
Not a direct answer or a better approach, sorry, but with the latest SimConnect SDK installed here (0.21.0.0), I do have `SubscribeToFacilities_EX1()` and `RequestFacilitiesList_EX1()` available in C#. Perhaps you need an update?

I take it you're reading the whole list and calculating distance to current lat/lon to find the closest? Hard to believe one has to jump through these hoops... but yea I don't see a SimVar for that. Unless one happens to have a runway selected (ATC RUNWAY AIRPORT NAME) or NAV tuned (NAV LOC AIRPORT IDENT) or selected as a waypoint (GPS APPROACH AIRPORT ID). With some help from a WASM add-on/Gauge API you could get access to GPS vars (<https://docs.flightsimulator.com/html/Programming_Tools/GPSVars/GPS_Variables.htm, eg. "NearestAirportCurrentICAO") but that doesn't help for pure SimConnect access.

Cheers,
-Max
 
In my app I can't assume there is a runway or freq tuned. And I can't assume anything about the aitplane, so I don't know about any gauges it has.
Funny, I uodated the SDK today, but didn't reaload it in VS, I'll check that when I get back home.
Actually iterating through all of them takes miliseconds, but it doesn't feel right
 
Thanks,
The whole thing worked great, I just had to add the reference again, to the updated dll.
Is there a way to tell if the type of the aircraft and the type of the airport (helipad, seaplane base, airport)?
 
Cool, good to hear.

I'm not sure about those others... For aircraft "type" there's "ATC TYPE" SimVar but I forget now what it returns (if anything). There are also several "IS GEAR *" SimVars but not sure if that gets you what you want. <https://docs.flightsimulator.com/ht...ake_Landing_Gear_Variables.htm#IS_GEAR_FLOATS>

For airport "type..." is that even a thing? (-: There's "SURFACE TYPE" for example, but that's again probably not what you're after... but otherwise, I don't know, sorry!
<https://docs.flightsimulator.com/ht...Vars/Aircraft_Misc_Variables.htm#SURFACE_TYPE>

Again in GPS variables there <https://docs.flightsimulator.com/ht...Airports.htm#NearestAirportCurrentAirportKind> so I guess "airport type" is indeed "a thing" but I don't see how to get there from SimConnect. :-/
 
It's probably not a thing... but i saw a problem with my logic. Although its should be an edge case. For example, starting a flight at KLGA on RWY22, the airplane is closer to seaplane base 2NY4 than to KLGA... if I could know that 2AY4 has only water runways and the airplane is a wheeled plane, I could eliminate many of these errors.
 
I am trying to detect where the user has landed. I can’t find a good way to deduce that information, so I had to resort to subscribing to facilities and checking distance from each of the returned airports (40,000 calculations).

  1. Is there no better way?
  2. The documentation says that using SimConnect_SubscribeToFacilities_EX1 can return only the airports in the reality bubble (which is 200 nm). However, the managed code dll only exposes a “SubscribeToFacilities” method. Is there a way to get only the ones in the reality bubble?
simconnect.SubscribeToFacilities(SIMCONNECT_FACILITY_LIST_TYPE.AIRPORT, DATA_REQUESTS.AIRPORTS_REQUEST);

I see an old post about a db lookup in FSLog - the file cannot be downloaded, but it seems similar to my approach?

Thanks!

I know its a little old, but your post in the one that shows up in google for searches regarding this so here's the solution.

enum DATA_REQUEST_ID { REQUEST_CLOSEST_AIRPORT, }; Assuming you already obtained your position and stored them in myLatitude / myLongitude // Get aiports in the reality bubble hr = SimConnect_RequestFacilitiesList_EX1(hSimConnect, SIMCONNECT_FACILITY_LIST_TYPE_AIRPORT, REQUEST_CLOSEST_AIRPORT); in your Dispatcher: case SIMCONNECT_RECV_ID_AIRPORT_LIST: { SIMCONNECT_RECV_AIRPORT_LIST* pAirList = (SIMCONNECT_RECV_AIRPORT_LIST*)pData; SIMCONNECT_DATA_FACILITY_AIRPORT* airports = (SIMCONNECT_DATA_FACILITY_AIRPORT*)(pAirList + 1); for (DWORD i = 0; i < pAirList->dwArraySize; ++i) { // Basic Euclidean distance calculation to find the closest airport double distance = sqrt(pow(airports[i].Latitude - myLatitude, 2) + pow(airports[i].Longitude - myLongitude, 2)); if (distance < closestDistance) { closestDistance = distance; closestAirportIdent = airports[i].Ident; } } if (closestAirportIdent != nullptr) { printf("Closest airport Ident: %s\n", closestAirportIdent); } break; }
 
Back
Top