问题
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!
回答1:
Google provides an API for this.
https://maps.googleapis.com/maps/api/timezone/<json or xml>?location=<lat>,<lng>×tamp=<unix timestamp>&sensor=<true or false>
eg:
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&sensor=false
回答2:
http://www.geonames.org/ provides an API that returns the timezone given a lat/lng
回答3:
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.
回答4:
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
来源:https://stackoverflow.com/questions/3867450/mapping-location-to-a-time-zone