mapping location to a time zone

别说谁变了你拦得住时间么 提交于 2019-12-10 19:02:05

问题


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>&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




回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!