Let's say we want to be able to calculate the distance that an aircraft flew, and over which countries it flew.
In this example, we will go through the steps necessary to recover the data from a flight and calculate the distance flown during the flight using the Tracking History API.
This tutorial assumes that you are already familiar Java Maven projects.
First, we will look at a specific airport, from which we will single out a specific flight to analyze.
Let's take CDG airport here. We will look at this GeoJSON representing the area of the airport:
Which is represented like that on a map:
Using the coordinates previously shown, we can filter the API results for the area we want:
- Latitude range:
48.970752,49.041694need to be South to North, so values can vary from
- Longitude range:
2.481443,2.642431need to be West to East, so values can vary from
Let's breakdown what we did here:
- We queried our endpoint around CDG airport during a specific time.
- We parsed the results and filtered out a single flight that fit the route we want (LHR to CDG).
Let's start by creating a new
Flight class, which will fetch the single flight data, and do the calculations.
Let's break down what we did here:
- We parsed the JSON object used in the constructor parameters.
- We fetched the flight of interest using its
- We parsed each line of the answer, and then prepared a method
calculateFlightDistancethat calculate the distance between two sets of coordinates, counting the total for all coordinates.
For this step to work, we will need to install the Atlas package, and add it to our Maven dependencies.
We can now add an additional method to our
Flight class. We will name it
Here is the expected output from our example: