dsheroh has asked for the wisdom of the Perl Monks concerning the following question:

I am working on yet another social networking site and the specced feature set includes allowing users to upload and geotag information (both photos and text). I'm largely unfamiliar with such things and google's not being particularly helpful, mostly just finding me information about how to use Perl to collect a list of coordinates from your GPS unit and insert them into the EXIF tags of corresponding photos. Not terribly relevant to what I'm doing.

My current thought is that the way to go would be to store both the user's entered location (for human consumption) and the latitude/longitude (for machine consumption) in the database with lat/long determined by using the first of these options which returns a match:

  1. Explicit user-entered lat/long
    This should be handled easily by a regex or two to identify and extract the coordinates.
  2. Lookup of user-entered place name in a geolocation database
    Geo::GeoNames will attempt to retrieve this information from the GeoNames web service, but I think I'd prefer to do it locally, since GeoNames provides downloadable dumps of their database and daily updates.
  3. Geotagging information within EXIF tags of photos
    I would expect this to be fairly simple with Image::ExifTool once I figure out which tag(s) to look for.
  4. Geolocation associated with user's IP address
    Geo::IP looks like it should do this with country-level granularity, but, while looking through google, I ran across a site which can do lat/long lookups down to city-level, which would be more useful to me (assuming I can find it again).
So, my questions, then:

Am I approaching this in the right way?
Have I found the appropriate tools to implement it or are there better options out there?

Replies are listed 'Best First'.
Re: Geotagging uploaded data
by Unforgiven (Hermit) on Jul 01, 2009 at 13:34 UTC
    As a quick disclaimer, I haven't done this before. But, for what it's worth, it sounds like a reasonable way to me. I might change the order, though, to 3,2,1,4.

    I figure that if you can do it without bothering the user who, for all we know, doesn't know longitude from latitude anyway, you may as well (as long as you always have the option for the user to override any of the others and manually set the location).

    Setting from the EXIF data first is sort of an extension of the user being able to override the automated methods, I figure, so go there first.

    Then, if that fails, try the web service. Failing that, just ask them. If they don't know either, use the IP address, which could be significantly off. At the very least, I'd use their IP address as a suggested value when you let them enter it manually, though.

    You could also just allow the priority of each of the four to be set by the user in their account settings, maybe under "advanced settings" or something.
      I agree with your reasoning, I just concluded that it supports the opposite order of things...

      The different conclusion is probably because I didn't explain the user interface involved. There are three input fields: One to enter text, one to upload a photo, and one to enter a geotag. All three fields are optional, although nothing will actually be done unless the user submits text and/or a photo, since there wouldn't be anything to geotag in that case.

      I figure that, if the user enters anything in the "geotag" field, then that should take precedence over any passively-obtained information and a more-specific entry (#1) should take precedence over a less-specific entry (#2) if both are present. If the user doesn't fill in the "geotag" field, or if their "geotag" entry isn't a recognizable location, then we fall back on information specific to the photo (#3), reserving the user's IP address as an absolute last resort (#4).

        Ah, I see what you mean. Yeah, I'd say that's a reasonable way to go about it.