Geonaming your Geotags – Automatic picture captions

This time last year, I wrote about how to Geotag your photos using a simple GPS device and oodles of free software. Not much has changed in that process since, except now there’s a lot more software to choose from and the clever folks over at have made it a lot easier to export your GPX tracks.

The spatially-aware web is producing a lot more services for us to use, and now some excellent reverse geocoding functionality. That’s the process of taking geo-data (such as longitude and latitude) and getting place names back. Which is really cool for tagging, titling or adding descriptions to your geocoded pictures.

They provide an impressive array of web services in both JSON and XML ranging from postal code searches, to reverse geocoding based on the community-based Wikipedia entries. And if that’s not enough for you, you can download a copy of their huge database and manipulate it off-line however you want.

So me, I wrote some JavaScript to take advantage of the reverse geocoding and tied it into the Blakepics Gallery2 Tags module. I’ll take the Wikipedia entries as an example, because that returns the most landmarks for me. The example code at the bottom of the page actually makes use of two more web services in addition.

The URL to call the web service is pretty simple enough:

var url = "" + lat + "&lng=" + lon + "&radius=10";

I’ve kept everything in JavaScript rather than building any back-end code whatsoever, so you need to make sure to use the JSON web services and take advantage of the script tags to avoid any cross-domain security policies. The JSONScriptRequest library can be a powerful ally here. This leaves my server to do more important things, but it all depends on your needs for the app.

url += "&callback=showWikipediaNames";
bObj3 = new JSONscriptRequest(url);
// Build the dynamic script tag
// Add the script tag to the page

Then on the callback
function showWikipediaNames(wikijsonData) {
var wikiobjects = wikijsonData.geonames;
if (wikijsonData.geonames) {
for (var i=0;i<wikiobjects.length;i++) {

With me so far? The final step in the process is to add the call to the JavaScript into your Gallery2 templates.

<a href="#" onclick="return showGeoNameOptions(this, {$}, {$block.gpsinfo.LoadGPSInfo.lon});">GeoNames</a>

And before you know it, you have suggestions from geonames on how to tag your photos. Now you can go away and make it suggest some titles and descriptions too. If anyone’s interested in packaging this up into a slightly better Gallery module (or any other application), drop me a line. If this is enough for you, download my example and use it as you see fit.



Tags: , , , , ,

Leave a Reply?