3

I need to get the time zone for a given address/location. Assume that the address/location can be reverse geocoded (using google) to a lat/lng if necessary.

This means that I may not have a zip code.

I was really hoping that google provided some kind of API for this, but it seems that they don't. At a minimum you can google search for "time in washington, dc" and get the time/TZ -- but then I'd have to screen scrape that which is not fun :(

I know there are databases available that map locations to time zones, but that'd have to be maintained. Has anyone come up with a tricky solution to this problem?

Thanks!

ChrisF
  • 134,786
  • 31
  • 255
  • 325
jsharpe
  • 2,546
  • 3
  • 26
  • 42

4 Answers4

4

Google provides an API for this.

https://maps.googleapis.com/maps/api/timezone/<json or xml>?location=<lat>,<lng>&timestamp=<unix timestamp>&sensor=<true or false>

eg:

https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&sensor=false

Dean Rather
  • 31,756
  • 15
  • 66
  • 72
2

http://www.geonames.org/ provides an API that returns the timezone given a lat/lng

jsharpe
  • 2,546
  • 3
  • 26
  • 42
  • 1
    geonames isn't free, the 'demo' account which the samples use is limited to only 3000 requests/day. I was using it for dev purposes just now and it flat-out stopped working. – Dean Rather Nov 12 '12 at 04:20
0

I've written a small Java class to do this, with the data structure embedded in the code. If you want to avoid using a web service, and accuracy of 22km is good enough, and you're happy to assume that timezone boundaries don't change, then it could help.

https://sites.google.com/a/edval.biz/www/mapping-lat-lng-s-to-timezones

Tim Cooper
  • 10,023
  • 5
  • 61
  • 77
0

The question needs to be clarified a bit more. What are you doing this for? What language(s) are you using? But how I would approach the problem is: First, create a table like structure that translates longitudes into zones(much like this table ). Next I would query the GMT either locally, or on the web somehow, and finally take the offset from the table and add it to GMT. This way there is no "maintenance" of the table since these longitudes don't change.

mpd
  • 2,223
  • 1
  • 19
  • 23