开发者

mapping location to a time zone

开发者 https://www.devze.com 2023-01-18 17:14 出处:网络
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.

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/T开发者_高级运维Z -- 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!


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


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号