Getting from geolocation (lat/long) to Time.zone


#1

Has anyone found a good solution for setting the Rails Time.zone from
a lat/long pair? I’ve been wrestling around with this.

The closest I can come is using the geonames API, but the problem is I
haven’t found anything that will do a decent job of converting from
their time zone namespace over to the Rails time zone namespace.

There are some hacks out there that use the UTC or GMT offset and
convert by finding a time zone with the same UTC offset between the
Geonames and Rails time zone sets. Unfortunately, it’s not a very good
hack because it ignores the fact that you might have multiple time
zones of different countries within the same UTC offset but with
different policies around daylight savings time. No to mention that
it’s a little wonky when someone enters a location near Capetown,
South Africa and the routine assigns them to the time zone for
Helsinki, Finland.

Is there anything that will do a better job of mapping, or am I just
using the wrong method entirely (i.e. is there a way to do this
without using the Geonames service at all?) It seems to me this is
probably something that has to be a service type situation, since
making a static mapping of all the time zones and then maintaining it
is probably impractical for a small site.

Thanks,
Tom


#2

Has anyone found a good solution for setting the Rails Time.zone from
a lat/long pair? I’ve been wrestling around with this.

You need a lat/long to timezone database- many are available, I’ve had
good luck with http://www.zipinfo.com/products/z5ll/z5ll.htm


#3

You need a lat/long to timezone database- many are available, I’ve had
good luck with http://www.zipinfo.com/products/z5ll/z5ll.htm

Forgot to mention- combine this database with something like
http://zipcodesearch.rubyforge.org/, and you’re good to go.

  • D

#4

I’m already using the geonames API… unless there’s a service out
there that returns names matching those in Time.zone it seems like
this would leave me with exactly the same problem.

On Dec 9, 1:06 pm, Danny B. removed_email_address@domain.invalid