Being a fairly regular JetBlue customer - they don’t fly everywhere but do most major cities across the US - I have come to enjoy checking out the back-of-the-seat heads up display of flight tracking. For a while they were using Google Maps but that display now uses OpenStreetMap as a basemap.

Ever since I started seeing wifi on JetBlue flights, via FlyFi, I also enjoyed looking at that flight tracker as well. If you are on a JetBlue flight go to http://www.flyfi.com/travel/ (this link won’t work if not currently on a JetBlue flight). FlyFi uses Google for mapping but hopefully they will transition to OpenStreetMap.

un FlyFi flight tracker

After staring at the FlyFi flight tracker map, I realized that since its served I could probably check out the code. After some searching through Google Chrome’s Developer Tools I was able to track down the javascript file. The portion of the code that loads in the new Lat,Lng’s was found below. (Note the highlighting of the word maps as finding that or map in a page is always a great way to track down map data, especially if there is a lot other stuff in the page.

un FlyFi javascript file with added Lat,Lng’s shown

Now using Chris Albon’s Plot Points On A Map blogpost, we can use Basemap to plot these Lat,Lng’s from this flight.

I then worked with this IPython notebook file which I’ll convert using a method I learned from an earlier blogpost Using IPython Notebook with Pandas and exporting to Markdown

IPython nbconvert jetblue-latlng.ipynb --to markdown

The IPython notebook code:

IPython notebook file

Import the modules

# Import pandas
import pandas as pd

# Import matplotlib and Basemap
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

# Set iPython to display visualization inline
%matplotlib inline

Read the lat,lng’s and format

inCSV = 'jetblue-gps.csv'

df = pd.read_csv(inCSV, header=None)

df.columns = ['lat_work','lng_work','drop']

df['latitude'] = df['lat_work'].str.replace('(','').str.replace('new google.maps.LatLng','')
df['longitude'] = df['lng_work'].str.replace(')','')

df['latitude'] = df['latitude'].astype(float)
df['longitude'] = df['longitude'].astype(float)

df = df[['latitude','longitude']]

df.head(5)
latitude longitude
0 40.472603 -74.006310
1 40.348148 -74.177799
2 40.167046 -74.771404
3 40.107994 -75.466461
4 39.916077 -76.197224

Make the plot with Chris Albon’s Plot Points On A Map blogpost

# Create a figure of size (i.e. pretty big)
fig = plt.figure(figsize=(20,10))

# Create a map, using the Gall–Peters projection, 
map = Basemap(projection='gall',
              # with low resolution,
              resolution = 'l',
              # And threshold 100000
              area_thresh = 100000.0,
              # Centered at 0,0 (i.e null island)
              lat_0=35, lon_0=-85)

# Draw the coastlines on the map
map.drawcoastlines()

# Draw country borders on the map
map.drawcountries()

# Fill the land with grey
map.fillcontinents(color = '#888888')

# Draw the map boundaries
map.drawmapboundary(fill_color='#f4f4f4')

# Define our longitude and latitude points
# We have to use .values because of a wierd bug when passing pandas data
# to basemap.
x,y = map(df['longitude'].values, df['latitude'].values)

# Plot them using round markers of size 6
map.plot(x, y, 'ro', markersize=6)

# Show the map
plt.show()

The points plotted

png