- static SGConstPropertyNode_ptr lat = fgGetNode("/position/latitude-deg", true);
- static SGConstPropertyNode_ptr lon = fgGetNode("/position/longitude-deg", true);
-
- // airport
- FGAirportList *aptlst = globals->get_airports();
- FGAirport *apt;
- if(argc == 0)
- apt = aptlst->search(lon->getDoubleValue(), lat->getDoubleValue(), false);
- else if(argc == 1 && naIsString(args[0]))
- apt = aptlst->search(naStr_data(args[0]));
- else if(argc == 2 && naIsNum(args[0]) && naIsNum(args[1]))
- apt = aptlst->search(args[1].num, args[0].num, false);
- else {
+ static SGConstPropertyNode_ptr latn = fgGetNode("/position/latitude-deg", true);
+ static SGConstPropertyNode_ptr lonn = fgGetNode("/position/longitude-deg", true);
+ SGGeod pos;
+ FGAirport* apt = NULL;
+
+ if(argc >= 2 && naIsNum(args[0]) && naIsNum(args[1])) {
+ pos = SGGeod::fromDeg(args[1].num, args[0].num);
+ args += 2;
+ argc -= 2;
+ } else {
+ pos = SGGeod::fromDeg(lonn->getDoubleValue(), latn->getDoubleValue());
+ }
+
+ double maxRange = 10000.0; // expose this? or pick a smaller value?
+
+ AirportInfoFilter filter; // defaults to airports only
+
+ if(argc == 0) {
+ // fall through and use AIRPORT
+ } else if(argc == 1 && naIsString(args[0])) {
+ const char *s = naStr_data(args[0]);
+ if(!strcmp(s, "airport")) filter.type = FGPositioned::AIRPORT;
+ else if(!strcmp(s, "seaport")) filter.type = FGPositioned::SEAPORT;
+ else if(!strcmp(s, "heliport")) filter.type = FGPositioned::HELIPORT;
+ else {
+ // user provided an <id>, hopefully
+ apt = FGAirport::findByIdent(s);
+ if (!apt) {
+ // return nil here, but don't raise a runtime error; this is a
+ // legitamate way to validate an ICAO code, for example in a
+ // dialog box or similar.
+ return naNil();
+ }
+ }
+ } else {