More mapping hacks

Volume 11, Issue 34; 31 Mar 2008; last modified 02 Nov 2010

Mapping photographs is one of those fun little projects that grows everytime I think about it.

Over the weekend, I realized there were three things I really wanted to add to my mapping hacks:

  1. Map all the photos on a given map, not just those with in 0.1 degrees of latitude/longitude from the center. As you zoom out, you should be able to see more images.
  2. Provide more control over the number of images mapped. Just because there are 600 images on the map doesn't mean you really want your browser to add 600 markers all at once.
  3. Figure out what places are most interesting, from a mapped photographs perspective.

And Dave's comment gave me another idea:

  1. Handle multiple photographs with the same latitude and longitude. This turns out to be more common than I would have expected because, I think, Flickr makes it easy to tag a batch of photos. SMOP.

Fixing the first two items was just a simple matter of programming. Along the way, I also improved the color coding so that its more consistent. My photos are still the only ones that get red pins.

The third was harder, but I can now produce a map and a list of places.

The line just below the map gives you more control over the markers. The following list of places includes everywhere that has at least one photograph. (This list will change over time as new geotagged photographs are added to Flickr.)

If you click on places in that list, the center of the map will move, showing you a selection of photographs near that place. The actual number of photographs shown depends on the zoom factor of the map.

Mapping a point on the earth to its closest landmark must be a well solved problem. I can imagine a variety of hierarchical data structures that would provide fast, accurate answers.

In my case, all of the computations are done “off line”. I don't have very significant performance constraints, so I went for the simplest thing that would work. The simplest thing, brute force, really won't work. Calculating great circle distances is computationally expensive, relatively speaking, and comparing each known point to all 84,000+ points in the list isn't practical. (I got the list by taking the GeoNames data and extracting all cities with a population greater than 1000.)

To make the searching practical, I divide the world into a grid of squares, each two degrees of longitude by two degrees of latitude. Into each square, I place all the cities with a latitude and longitude that falls within that square or within one degree of latitude or longitude in each direction. (So a 4x4 square centered on the 2x2 square.) This extra “sloppiness” solves the boundary problem well enough, at least, for my purposes.

Given a random coordinate, I can quickly find the relevant square. I then do a brute-force search of all the cities in that square. If there aren't any cities in the starting square, I search outward, building a larger and larger square until I find one big enough to contain at least one city.

Then it's just a simple matter of collation. Just for fun, I'll see if I can make a simple web service out if this bit of code.

Comments

Vancouver Canada is listed as Vancouver CA for some reason..

—Posted by Dave Orchard on 31 Mar 2008 @ 09:40 UTC #

It didn't do well with Galway. When I clicked on Galway, it went to the coast near the Burren rather than Galway. And a bunch of pictures we took in Galway don't show up, such as parade

—Posted by Dave Orchard on 31 Mar 2008 @ 09:46 UTC #

"CA" is the ISO country code for Canada, Yes? If there is a Vancouver in California, it'll appear as "Vancouver, CA, US".

I'll see about centering the pictures better. At the moment, I simply uses the median latitude and longitude of all the photos identified as being in a particular place. For Galway, that seems to produce odd results. Maybe I need to adjust the scale, or weight the results, or something.

Finally, the "Parade" picture isn't identified as geotagged. Did you place that picture on the map by hand, or add GPS information to the EXIF? I'll see if I can find an efficient way to get Flickr to tell me about its location.

—Posted by Norman Walsh on 31 Mar 2008 @ 10:56 UTC #

Very cool application. But, I noticed that all of the pictures I tried to view on your local page (the one with your pictures) have broken links to flickr. The thumbnail pops up fine, but when you click on the picture, flickr comes up with a "bad link" page.

I had no problem with any of the other locations I tried.

—Posted by Dick Hamilton on 31 Mar 2008 @ 11:02 UTC #

I figured out the "Parade" picture. You have a whole series of images with exactly the same latitude and longitude. Because the resulting marks would be exactly on top of each other, and there's no notion of "z-order" AFAICS in Google Maps, a marker is only generated for the first image on any given coordinate.

I suppose I could see about generating something like "And nn more images at the same spot" or something. Maybe.

—Posted by Norman Walsh on 31 Mar 2008 @ 11:04 UTC #

How embarrassing, I couldn't get my own photo links right. Fixed now. Stupid implementation hack that leaked out.

—Posted by Norman Walsh on 31 Mar 2008 @ 11:09 UTC #