Google

Visualizing Location History

Friday, July 25, 2014


If you, like me, use Location History in Google services to enhance and unlock a more personalized experience, now thanks to a few nifty python scripts you can visualize all that history and render it on a jpeg image.

You can already do this using Google's location history dashboard here, but you are limited to only a selected range up to a maximum of 30 days, if you want to visualize all your Location history then that's not an option.

Below I have included an example location history map, which is what we will be making in this tutorial.


What you'll need

If you choose the simple route just download my zip file here: Visualizing Location History.zip which contains everything you need including some batch files to make the process easier, just extract it somewhere. Python and PIL(Python Imaging Library) are in the install folder, you will need to install these in step 1.

For the rest of you, heres what you'll need.
  1. Python (https://www.python.org/downloads/) Make sure to get version 2.7.x at time of writing PIL does not support version 3.x.x
  2. PIL, the Python Imaging Library (http://www.pythonware.com/products/pil/) make sure to get the right version for your version of python e.g. if Python 2.7 get PIL for Python 2.7
  3. The following scripts:
Step 1: So to start things off we'll get the easy parts out the way, first install Python and PIL, these are simple installations.

Step 2: Next you will need to get a copy of your location history from Google Takeout (https://www.google.com/settings/takeout)
Click the create archive button then click select all to deselect all the other options, we only want the location history for this tutorial. Select the Location History check box then click create Archive at the top of the page. It may take a little while to create your archive but it shouldn't take too long being just a json file, Google will send you an email when its ready for download.

Step 3: Once you've got your location history downloaded extract it into the folder called "converter", then just double click the .bat file I created and that will convert your JSON file into a KML file for use when we draw the location history ontop of your map.

Step 4: Copy the KML file created in the previous step and put it in the "generate" folder.

Step 5: Before we can draw the location history we need an image to draw it on, this step can be a little tricky, what we need to do is get a satellite image, but we have to know what coordinates are at the top left corner and at the bottom right corner. There are probably other ways to do this but I'm going to show you the way I have done it.

First you will want to open up Google maps, find the area you want to save for your location history, now look at where your top left corner is going to be, try to find a place you can remember for when you crop the image such as a unique curve in a road, or a darker blue in the water, it all depends on where you are in the world.

you will want to do the same with the bottom right corner, find something unique that you can remember, once you have done this for each corner you will need to right click and click the option "What's here?" a card will pop up with the coordinates of that location, copy these down. I will now visually show this process.
Here I have selected my first point in this area between here the water is darker and lighter, somewhere unique that I can remember. I have right clicked and then clicked "What's here?"

Here you can see the point at the coordinates on the map and I am copying the coordinates of this point, paste them into notepad or anything else just for temporary storage as you need to copy the next lot aswell.

Here I have selected my second location in Mount Barker where these two roads come together which is something I can remember, I have copied the coordinates into notepad along with the others.

Now you need to press the [prt sc] button on your keyboard to take a screen shot and paste it into paint or any other image editing software, crop the image to the two points you have selected and save the image as map.jpg in the generate folder.

Step 6: Now we need to put the coordinate of our map image into a csv file so the python script knows what coordinates are where on the image and what it can draw on the image, open the ImageData.csv with notepad.

Now you cant just paste the coordinates in, you have to put them in the right order, the csv file uses the following format: [IMAGE NAME],[LAT_TOP_LEFT_CORNER],[LAT_BOTTOM_RIGHT_CORNER],[LNG_TOP_LEFT_CORNER],[LNG_BOTTOM_RIGHT_CORNER],[0],[0]
incase you don't know, the first part of the coordinates are the Latitude and the second part is the longitude like the following image demonstrates



So this is what my csv file now looks like:

map.jpg,-34.586334,-35.019697,138.294263,138.942461,0,0

Save your CSV file and that's that, all the hard work is done.

Step 7: Now all you have to do is double click the generate.bat file and after a little while a file will appear called "LatitudeData.png" this is your final image.

I hope you enjoyed this tutorial, it's my first ever! this was a little complex especially for beginners but I hope you were successful and got it all to work!

and thats how luke see's it!




Popular Posts

Like us on Facebook

Flickr Images