Java FlightXML Program Print Altitudes

I am using the Netbeans version of the Flight XML Java code. I was wondering if there is a way to print out all the altitudes and timings for a flight, given the airline and flight number. Does anyone have any code that does this, or any tips on what methods and classes to use?
Thanks for the help!

I found this: http://flightxml.flightaware.com/soap/FlightXML2/doc#op_GetFlightID (the getHistoricalTrackInformation operator)

Now the problem is that I don’t know where to find the faFlightID. I would use the getFlightID operation, but I don’t have an enterprise membership, thus I do not have access to the ident. Is there a workaround for this?

Thanks!

FlightInfoEx includes the faFlightID of each flight that it returned.

Can you show me an example of how to use that to get the data I need?

Given a specific flight I’m looking for something along the lines of:

Time Alt
3:34 1000 ft
3:40 15,000 ft
etc.

Call FlightInfoEx with the ident of the flight you are interested in (such as the most recent one that has arrived), then call GetHistoricalTrack to get the position data for it. Here’s some pseudocode:



flights = FlightInfoEx(ident => "UAL5",  howMany => 10, offset => 0);
foreach (flight in flights) {
   if (flight.actualdeparturetime > 0 && flight.actualarrivaltime > 0) {
       track = GetHistoricalTrack(faFlightID => flight.faFlightId);
       foreach (pos in track.data) {
          println EpochToHuman(pos.timestamp), pos.altitude
       }
       break
   }
}


Thank you!

FlightInfoExRequest flight_req = new FlightInfoExRequest();
flight_req.setHowMany(1);
flight_req.setIdent(“UAL468”);
flight_req.setOffset(0);
FlightInfoExResult flight = df.**FlightInfoEx(**flight_req);
if (flight.actualDepartureTime > 0 && flight.actualarrivaltime > 0){
GetHistoricalTrackRequest track = new GetHistoricalTrackRequest();
track.setFaFlightID(flight.faFlightID);
for(pos:track.data){
System.out.println(EpochToHuman(pos.timestamp) " " pos.altitude);

    }
}

Here is my code so far. The parts in red are where I am getting errors. Can you tell me what is wrong?

Also, how can I tweak the code to give me the altitude data for a specific flight. For example the UAL468 flight on April 9th from SEA to SFO at 7:41am (http://flightaware.com/live/flight/UAL468/history/20150409/1425Z/KSEA/KSFO). Is there an ID for that specific flight, and if so, where do I find it and how do I incorporate it into my code?

Do not use howMany of 1. You will only get one flight (and that is probably not the one flight you want, since it is likely to be a future flight that hasn’t occurred yet). FlightInfoEx will be returning an array of flights, even if it is an array of 1 element.

For the Java, you will need to actually look at the auto-generated interface bindings that were produced by the Axis command-line program, in order to figure out the names of the classes and methods. Most of the structure members are accessed using accessors, rather than directly, I think. (For example actualDepartureTime and actualarrivaltime)

The function “EpochToHuman” does not actually exist, since my example was pseudo-code. You will need to find the appropriate conversion for Java, or implement your own. Additionally, I think Java will require you to combine those strings using “+” at least.

I’m sorry, I’m not sure I understand what you mean by “Most of the structure members are accessed using accessors”. How would you suggest I change my code? I’m pretty new to Java, so I need a little more help, please. Thanks!

Did you run the wsdl2java.sh utility yet, as shown in the example? You need to do that before attempting to develop against any of these interfaces. Once you’ve done that, you will be able to explore the generated java interface file and see what the automatically generated names of the structures and methods are, and how they are nested.

In Java, an “accessor” is a method to get or set a member variable. For example, “setHowMany()” is a setter method for the “howMany” variable, which you would not simply access directly.

If you are unfamiliar with Java development and encountering syntax errors during compilation, you may want to seek other programming books/references first, as I am not prepared to teach programming fundamentals.

is there any other condition (except departure and arrival times) which can filter out useless flight IDs? for example, I am trying to get tracks of BAW2653, so I called


https://flightxml.flightaware.com/json/FlightXML2/FlightInfoEx?ident=baw2653&howmany=1&offset=0

to get flight IDs for future use with GetHistoricalTrack. it returned 15 (I dont know why when I set howMany to 1) results, including


{"faFlightID":"BAW2653-1487571930-airline-0283:0","ident":"BAW2653","aircrafttype":"A320","filed_ete":"01:54:00","filed_time":1487681960,"filed_departuretime":1487757900,"filed_airspeed_kts":332,"filed_airspeed_mach":"","filed_altitude":0,"route":"","actualdeparturetime":1487758080,"estimatedarrivaltime":1487764500,"actualarrivaltime":1487764511,"diverted":"","origin":"LOWS","destination":"EGKK","originName":"Salzburg (W. A. Mozart)","originCity":"Salzburg, Salzburg","destinationName":"London Gatwick","destinationCity":"London, England"}

and when I use this one in a call


https://flightxml.flightaware.com/json/FlightXML2/GetHistoricalTrack?faFlightID=BAW2653-1487571930-airline-0283:0

the result is “{“error”:“no data available”}”

You are calling it with “howmany” not “howMany” (case sensitive), so the argument was ignored.

In any case, you do not want to pass 1 for howMany… You definitely want more than one so that your application can pick which flight it wants. The first one is almost always not the one most people actually want, since that is one furthest in the future that we are tracking.

That also explains why GetHistoricalTrack is failing for that flight. It is so far in the future that it has not occurred yet and we do not have a track for it yet.

thanks! it was my mistake with the case sensitivity :unamused:

the second explanation, maybe my calculator is wrong, but I think it wasn’t about future. based on the timestamp that flight occurred before my call/post (flightID: 1487571930 = Monday, February 20, actual duration of the flight: Feb 22 from 11:09AM to 12:54 PM, my call: Thu Feb 23, 2017). Now, with the same call I get a valid result.

The number in the flight ID has nothing to do with the time of the flight. Flight IDs are opaque identifiers, you shouldn’t try to interpret them.

that’s exactly why I emphasized also that the flight itself occurred a day before my query

GetHistoricalTrack is generally intended only for past flights that have already arrived. (There may also be a slight database replication delay of a few minutes between when a flight arrives and when it is available from GetHistoricalTrack.)

If the flight is still the most recent flight then GetLastTrack can still be used.