zsmb's prog site

GLocTagger

  2016.08.06.

Introduction

Do you have a camera that doesn't have a built in GPS? Do you have Google location reporting enabled on your phone? Do you like having GPS tags in your image files? Probably not. But I do. And here's my solution for the described situation that adds location taken from your Google account to your JPEG images' EXIF data.

Description

This is something that I made for my own personal use because my answer to all the questions posed above is yes. I wanted to have a way to put at least a reasonably accurate GPS tag on my photos taken from my camera before putting them into storage - meaning both local and Google Photos, the latter of which can benefit from this greatly when you're searching for your photos later.

The inspiration for this actually came from Google themselves, since they provide a similar feature in Google Photos, showing estimated locations for photos you've taken, using the location data they have about your phone; I just wanted a more substantial solution that would actually write data into the files. You can read about the Google Photos feature  on AndroidPolice.

Using it is fairly painless, and it can process basically any amount of photos in one job. The only real limit to its speed is the storage you're using, it basically runs at the same speed as you could copy your photos from one folder to the other. You need to download your location data from Google Takeout as I described  in this article, and then all you need to do is point the program at the JSON file you got, the folder where your photos are, and add some additional options and tweaks. I used this for hundreds of images from holidays this summer, and I'm very satisfied with the results I was able to get.

Usage

For this part, see the  GitHub repo of the project.

Development

There were a couple of interesting problems to solve along the way here, but once I verified that each individual task that I needed to be able to do is possible, it was smooth sailing for the part where I put it together. Let me mention just a few of the solutions that I used.

I needed a way to read the time the photos were taken from the image files, and then add the location data to them. The solution I found for this was the  Apache Commons Imaging library (formerly called Sanselan). This was fairly painless to use and there is plenty of good example code to find, some of it doing the exact thing that I needed to do.

Then there was the question of parsing the JSON file containing the location data. I ended up using the  Jackson library, specifically the data binding features, which are extremely convenient, since they allowed me to create thousands of simple dummy objects ( POJOs) that I could then use to create my more complex objects. All with just a couple lines of code, great stuff.

Lastly, I had to calculate distances between GPS coordinates given by latitude and longitude values somehow. This is far from a trivial problem. One of the popular and pretty accurate solutions is the  Haversine formula, for which I found an already coded implementation on  this website.

Downloads

You can find the source code in the  GitHub repo and download the latest binary release from the  GitHub releases page.

Below are mirrored versions of the releases.

Name Description Size Date
GLocTagger.jar Java executable (v1.0) 1.99 MB 2016.08.06.