Geotagging your photos after the hike

It is possible, but call your geek friend

When I posted my photos from the John Muir Trail in social media, there were a couple of photos where people disagreed with my captions.

Is it Sallie Keys lake or is it Marie lake?

It is hard enough to remember exact locations on a day hike, but on a 13 day hike where every turn is spectacular, it is impossible to remember exactly where you shot a photo.

Geotagging is a mechanism by which you tag every photo you take with the GPS co-ordinates of the location you shot the photo from. Photos taken from smartphones typically have this information embedded in them. For mirrorless cameras like the Nikon D50, you need to buy a GPS unit like the GP-1 and attach it to your camera. This embeds the GPS co-ordinates to the photos as you take them.

However, these devices use up battery and that is the one scarce commodity in the wilderness.

I was looking at options to geotag the photographs after the hike is done. I realized that I was tracking my hike through my Apple Watch, which as it happens, records my latitude and longitude every second of the hike.

The standard format in which this is shared is called GPX. Once you export a GPX file, multiple pieces of software can then read it. For instance, reads this to present the hike in a nice format.

Relive video of the entire hike Substack makes it hard to embed video inline, so you have to click through. Again, check the interactive mode. It is pretty cool…
Read more

The idea is very simple. Each photo taken has a capture time. If I can take the capture time from the photo and lookup a corresponding time entry in the GPX file, I should be able to get the latitude and longitude.

There is a tool called exiftool on most operating systems that tells you photo meta information. For instance, when I ran exiftool on one of my photos, I get this:

Date/Time Original : 2021:07:14 15:23:55.43-05:00

The GPX file for my hike contains this information for each second

<trkpt lat="37.7830670" lon="-119.1277040">

The time in the GPX file is in a different format. Once you reconcile the timestamps, it should be fairly easy to automatically update the GPS co-ordinates on photos.

You really don’t have to do this for all your photos. You can simply look up the GPX file for lat long for photos you have questions.

Nonetheless, since I am a programmer by day trade, I wrote a quick, ugly version of scripts to do this. The source code is committed here and is free to use.

  • This extracts just the lat / long and timestamp from the GPX file and writes it to a YAML file. This wasn’t really needed, but XML is slow to parse and it was driving me crazy. For my JMT hike, it took over 5 minutes to parse the XML files.

  • This walks through all RAW images in a directory, gets the timestamp of photo capture time, compares it to the lat / long from the YAML file and if co-ordinates are found, update the GPS coordinates stored in the photo as EXIF and saves it.

This seems to work. Spot checking photos indicates this works.

Where does this not work?

  • If you are not tracking your hike, typically photos taken after you setup camp, the location is not set, but hopefully these are easy to track and remember.

  • The code is ugly. There are timezone hacks in the code are ugly. This is definitely not production ready and I would not recommend anyone who is not code savvy to do this.

There should be a better solution. I also own Photo Mechanic Plus which has a beautiful GUI to do just this. However, spot checking that, I found some photos were way off their location and were defaulting to a specific location from day 1. I am not sure what is going on there. Until I figure out what is going on, I won’t recommend it. I plan to reach out to their support today and I will update when I hear an answer.