I figured out how to use FGAirport::findClosest to accomplish what I needed:
static SGConstPropertyNode_ptr latn = fgGetNode("/position/latitude-deg", true);
static SGConstPropertyNode_ptr lonn = fgGetNode("/position/longitude-deg", true);
SGGeod pos;
FGAirport* apt = NULL;
AirportInfoFilter filter;
static SGConstPropertyNode_ptr lonn = fgGetNode("/position/longitude-deg", true);
SGGeod pos;
FGAirport* apt = NULL;
AirportInfoFilter filter;
double maxRange = 10000.0;
pos = SGGeod::fromDeg(lonn->getDoubleValue(), latn->getDoubleValue());
apt = FGAirport::findClosest(pos, maxRange, &filter);
string id = apt->ident();
The above results in id being the single nearest ICAO. Throw this in a loop and iterate the pos lonn/lat the amount of the loop iterator, put the results in an array, then choose a random ICAO from the array using rand(). Then you have a list of ICAOs N, S, E, and W from your current location. The longer the loop or the greater the iterator, the further away the ICAOs go. For example:
for (float i=.1; i < 5; i = i + .1)
{
pos = SGGeod::fromDeg(lonn->getDoubleValue(), latn->getDoubleValue() + i);
apt = FGAirport::findClosest(pos, maxRange, &filter);
string id = apt->ident();
dest[x] = id;
x = x + 1;
}
{
pos = SGGeod::fromDeg(lonn->getDoubleValue(), latn->getDoubleValue() + i);
apt = FGAirport::findClosest(pos, maxRange, &filter);
string id = apt->ident();
dest[x] = id;
x = x + 1;
}
In the above dest[] will contain 50 ICAOs. Some will be duplicates since a .1 increment in latitude may result in the same airport being the nearest. But that can be tweaked to one's need.
gapalp
-------- Original Message --------
Subject: [Flightgear-devel] airport list
From: <[email protected]>
Date: Mon, April 09, 2012 6:34 pm
To: "FlightGear Development" <[email protected]>
I just started playing around in FlightGear development and wanted to intro myself. You all have a great piece of software here and I am enjoying it. I come from years of flight simming in other programs and doing some small commercial work in them. My day job involves corporate app development. My hobbies are astronomy, flight simming, and coding.Anyway, I am playing around with a cargo manager for FG. I have run into needing to pull an airport list to use in a random cargo job generator. Airinfo() and navinfo() don't appear to do it for me. Any way to get the list using an available C++ function? Just a list of ICAOs would be a start. Or will I need to read/parse through the apt.dat file?Thanks and I look forward to some coding fun :)gapalp
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel
------------------------------------------------------------------------------ Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________ Flightgear-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/flightgear-devel

