UPDATE 2/26/2024: Google has updated its format for location history (and renamed it Google Timeline), so I rewrote a bunch of this code for the new format (and got rid of the need for a Google API key). New post here: https://www.bricoleur.org/2024/02/google-timeline-to-countries-and-dates.html.
I had some spare time, so I knocked out another rough and ready set of scripts that I've been meaning to code for a while (see also DenseDead). These scripts, written in python with help from the Google Geocoding API, Google Charts, and the GeoPy module will give you a map of the world with countries colored based on how many years it has been since you visited. Mine looks like this (I added some data by hand for before 2012):
It is kind of kludgy, but in case you are curious, the steps and the scripts are below.
One of the reasons I wanted to write these is because the Google information is awesome but both too detailed for what I'd like to keep lying around, and not useful to me as latitude/longitudes. Instead, I'd like to know the countries I've been to over time. With these scripts, I convert the timestamps and latitude/longitudes into timestamps and addresses before fuzzing them down to years and countries, which is immediately useful and about the level that I want to keep. If you no longer find Google's use of its more fine-grained information useful, you can also clear the more detailed information from Google (instructions to delete your location history).
reduce_kml.py
get_addresses.py
fuzz_address.py
make_country_chart.py
It is kind of kludgy, but in case you are curious, the steps and the scripts are below.
One of the reasons I wanted to write these is because the Google information is awesome but both too detailed for what I'd like to keep lying around, and not useful to me as latitude/longitudes. Instead, I'd like to know the countries I've been to over time. With these scripts, I convert the timestamps and latitude/longitudes into timestamps and addresses before fuzzing them down to years and countries, which is immediately useful and about the level that I want to keep. If you no longer find Google's use of its more fine-grained information useful, you can also clear the more detailed information from Google (instructions to delete your location history).
- Go to Google Takeout and download a KML of your location history. Allow me one small digression here.
<DIGRESSION>
Google Takeout exists because of a relatively small group of engineers and others at Google who worked hard to make it exist. The team used to go by the name of the Google Data Liberation Front and have a really cool website and logo. The website now redirects to a support article but there are still great people working at Google working on ensuring that users have access to their data. This type of data portability is extremely important and ensuring it is something I worked on in the private and public sector. Thank you to the current and former team members and allies of the Data Liberation Front!
</ DIGRESSION> - Run reduce_kml.py to reduce the number of KML entries to a more manageable number. I threw out all entries that are within 10miles of the last entry I counted. The commandline is:
#python reduce_kml.py Google_Location.kml > outfile.kml - Split up the resulting file into chunks so that you don't violate the Google Geocoding API's daily limit. I used "#split -l4000 output_from_reduce.kml infile" that will produce 2000 calls to the Google API per file.
- Run get_addresses.py on each of the split files. Do one per day so as not to get blocked. The commandline is:
#PYTHONIOENCODING=utf-8 python get_addresses.py input_file.kml
Note that I needed to specify the encoding because although I think I understand encoding well enough, I don't. If someone else wants to teach me how to fix that, I would love to know. - Join the outputfiles ("#join infileaa infileab infileac > infile_join").
- Optional: Fuzz the joined outputfiles by using fuzz_addresses.py:
#python fuzz_addresses.py inputfile.csv outputfile.csv - Run make_country_chart.py to create an HTML file that will include the javascript for the chart. The commandline is:
#python make_country_chart.py input_file.csv > Country_Chart.html
You may download the scripts at amac0/google-location-tools and the most interesting are also below.
get_addresses.py
fuzz_address.py
make_country_chart.py