#47: finding a time zone give lat/lon coordinates

A little while ago we started using time zones in iNat, which was more troublesome than anticipated. One problem I ran into was automatically setting the time zone from pre-existing observations given their lat/lon. I ended up http://www.earthtools.org/webservices.htm, which is a fine little service, but I didn't end up incorporating it into the app because I didn't feel like implementing the caching restrictions they ask for (yes, I am insanely lazy). So...

use the flickr API

The Flickr API is amazing. using the places.findByLatLon method, you can not only reverse geocode your coordinates, but each place response comes with a a TZ time zone identifier! TZ is the database used by the Rails time zone stuff, so it's perfect for use in rails. Here's a trivial example using the excellent flickraw gem:

o = Observation.first places = flickr.places.findByLatLon(:lat => o.latitude, :lon => o.longitude) o.time_zone = ActiveSupport::TimeZone::MAPPING.invert[places.first.timezone]

Also, it's Flickr, so pretty robust and open.

Think you've got a better solution? Help 148c663fd665c53518538e093ce3c2ab_small kueda out by posting your solution