Determine timezone from latitude/longitude without using web services like Geonames.org

Jacek Francuz picture Jacek Francuz · Apr 7, 2011 · Viewed 45.5k times · Source

is there any possibility to determine the timezone of point (lat/lon) without using webservices? Geonames.org is not stable enough for me to use :( I need this to work in PHP.

Thanks

Answer

Michael Borgwardt picture Michael Borgwardt · Apr 7, 2011

I had this problem a while back and did exactly what adam suggested:

  • Download the database of cities from geonames.org
  • convert it to a compact lat/lon -> timezone list
  • use an R-Tree implementation to efficiently lookup the nearest city (or rather, its timezone) to a given coordinate

IIRC it took less than 1 second to populate the R-Tree, and it could then perform thousands of lookups per second (both on a 5 year old PC).