offset \ˈȯf-ˌset\ noun

a force or influence that makes an opposing force ineffective or less effective

Displaying Location Name from Image Coordinates in Google Earth with Python

A while ago I made a Python script that takes your images and extracts the latitude and longitude coordinates for KML from them. The KML can then be opened with Google Earth where you can enjoy the fancy display of your photos attached to map locations. The script works in the way that it creates placemarks in KML that are correctly placed on the map. When one clicks the placemark, it opens a popup with the image associated with that location.


However, the description is just a timestamp of when an image was taken. That bugged me and there was a better way to get the information about the location, too. The format I opted for was "Photographed at {timestamp} near {location_description}". Quite better than just "{timestamp}".

Since I already had the timestamp to work with, that part was easy, but the other one, where I needed to figure out the location was a bit more tricky. I relied on a public openstreetmap reverse geocoding API to get the information about the specific coordinates. To comply with their terms of service, I needed to avoid bulk querying and query the service only once per second. I also needed to keep a cache of locations so the repeated coordinates didn't need to query the service.

The algorithm in question is simple enough. To get that, first check the cache if it has the location already and return that. If not, pause for two seconds because I don't want to take any chances and then query the service with the requests library, cache the response and get the location description. The requests naively retries for a couple of times just to be sure and drops it if it times out.

The result is a bit more easy to comprehend.


Now, the name that gets into the title also bugs me, but I'll explain the fix I did in the next post.