---
title: "Command-line photo geotagging"
date: 2017-10-13
url: https://fortes.com/2017/command-line-photo-geotagging/
summary: "Using Google location data in order to geotag photographs from a camera via the command-line"
---

In [our last installment](https://fortes.com/2015/command-line-photo-organization/), I
walked through the steps I took to get a "good enough" filesystem layout for my
multi-decade digital photo collection. I've since uploaded everything to [Google
Photos](https://www.google.com/photos/about/) and have been pretty happy with
how things work.

One nice feature Google Photos provides is the ability to easily search photos
by geographic location. Their system is smart enough to grab a bunch of metadata
based on the GPS coordinates. If you've given into the cloud, you can try this
yourself by searching some location names. They support city, state/province,
and country; they also seem to support a limited set of finer-grained locations
such as universities or airports.

![Google Photos suggesting geographic search queries](<https://fortes.com/2017/command-line-photo-geotagging/2017-google-photos-geo-search.png>)

Of course, this only works if your photos have been geotagged (although Google
can sometimes [estimate your
location](https://support.google.com/photos/answer/6153599?co=GENIE.Platform%3DAndroid&hl=en-GB)
even without GPS coordinates). Photos taken on the phone camera will pretty much
always have GPS data (unless manually disabled), so the vast majority of my
photos are already correctly tagged.

However, I still lug around a non-phone camera every once in a while, but
unfortunately not one of the few [GPS-enabled
cameras](https://en.wikipedia.org/wiki/List_of_cameras_which_provide_geotagging)
so I continue to generate untagged files and bring shame upon my family. I'm
pretty obsessive about metadata, but I'm not dropping a bunch of money on a new
camera just to get GPS tags.

It's tempting to settle for Google's automatic location detection, but I've
learned to hedge my bets ever since [they broke my heart by killing Google
Reader](https://twitter.com/fortes/status/639208551462735872).

Fortunately, Google's frighteningly effective panopticon can be tapped for our
needs in this situation. If you've never checked out your [Google Maps
Timeline](https://www.google.com/maps/timeline), you may be shocked at how
thoroughly your geographic past has been preserved. Fortunately, we use this to
our advantage in order to annotate our non-smartphone images (this is almost
certainly the same data used to estimate location in Google Photos). Within your
timeline, you can export your coordinates to a KML file.

![Exporting a trackfile from Google Timeline](<https://fortes.com/2017/command-line-photo-geotagging/2017-google-timeline-export.png>)

Once you've downloaded that KML file, you can use our metadata Swiss Army knife
[Exiftool](https://www.sno.phy.queensu.ca/~phil/exiftool/) to automatically
geotag all your photos from that day:

```bash
# Warning: Updates metadata and overwrites original files
exiftool -overwrite_original_in_place -geotag history-2017-09-27.kml -r images/*
```

Unfortunately, there is no API for the Google Maps Timelines, so you have to
repeat this process manually for each day you're looking to process photos from.
Alternatively, you can [export your entire
history](https://takeout.google.com/settings/takeout?hl=en&gl=US&expflags), but
it takes a while before you get all the files.

Once again, we've found a nerdy, cumbersome, and partial solution to a problem
well-adjusted humans spend zero time thinking about. Success!

## Related

- [Adventures in command-line photo organization](<https://fortes.com/2015/command-line-photo-organization/>)
