## Step 1: Download your Google Location History Google makes this process very easy. Go here to [download your location history data](https://www.google.com/settings/takeout) and unzip it. # Import pandas import pandas as pd # Import matplotlib and Basemap import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap # Import decimal import decimal # Set iPython to display visualization inline %matplotlib inline # Create a dataframe from the json file in the filepath raw = pd.io.json.read_json('/Users/chrisralbon/Downloads/Location History/LocationHistory.json') # View the last five rows of the dataframe raw.tail() # Expand the locations column into a dataframe # This lets us move down one level in the json structure df = raw['locations'].apply(pd.Series) # View the last five rows of the dataframe df.tail() # Create a list from the latitude column lats = df['latitudeE7'] # Create a list from the longitude column lons = df['longitudeE7'] # Multiply both lists by -E7 to move the decimal point # to the correct location lats = lats * 0.0000001 lons = lons * 0.0000001 # View the last five list elements list(lons[-5:]) # Set the precison of getcontext decimal.getcontext().prec = 6 # Convert the float into a decimal string, then put it back into float lats = [float(decimal.Decimal("%.6f" % e)) for e in lats] lons = [float(decimal.Decimal("%.6f" % e)) for e in lons] # View the last five list elements # to check the decimal function worked list(lons[-5:]) # 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 = 'h', # And threshold 100000 area_thresh = 100000.0, llcrnrlon=-0.186768, llcrnrlat=51.454007, urcrnrlon=-0.061798, urcrnrlat=51.530960) # 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 x,y = map(lons, lats) # Plot them using round markers of size 6 map.plot(x, y, 'ro', markersize=6) # Show the map plt.show()