Shared publicly  - 
 
There are some great libraries both for iOS and Android to display the current time given a timezone identifier and there is a free database available for those (http://en.wikipedia.org/wiki/Tz_database). Figuring out what timezones a country has based on that is quite doable.

But how do you get the timezone for a specific city (preferably the timezone for any given lat/lng)? Other than looking up the pixel color in the map on the wikipedia article :)
1
Martijn Vos's profile photoNelson Minar's profile photoWillem Mulder's profile photoKaushik Sridharan's profile photo
10 comments
 
The Google Map API can map addresses, cities and countries to lat/lng. What you need is something that does the opposite. Couldn't this be a hidden feature somewhere in the GMap API? I have no idea.
 
Google can do the reverse too and you can also use openstreet maps if you want to keep things open.

What I need through is a way to go from cityname to timezone. The tz database obviously only has a limited number of cities in there.
 
I think this problem is subtle. Naively you'd just walk up the hierarchy of locations (city, county, state, country) until you find a time zone. But there's all sorts of weird exceptions.
 
Doesn't the tz database specify which countries or provinces fall in which timezone? Surely somewhere there has to be a more accurate definition of the borders of timezones than just the Area/Location timezone names?

+Willem Mulder Note that the solution you link to isn't completely accurate. It's quite possible that the nearest city is in a different timezone.
 
+Martijn Vos True, best would be to know the exact shapes of the timezones in terms of lat/lang coordinates. I however don't know if a formal definition in these terms exists?
 
+Nelson Minar Kentucky has three timezones (http://en.wikipedia.org/wiki/Time_in_the_United_States#United_States_time_zones). From the names of the zones it is hard to figure out what county belongs to which, only which cities (also getting a really accurate geographical hierarchy where the names have to match exactly.

+Willem Mulder The world cities list is certainly useful if your city is in one of the 15000. Outside of that it is still an educated guess (matching the hierarchy like Nelson suggest would mostly work I guess). For villages in the Hopi nation in Arizona it probably won't work though.
Translate
Add a comment...