Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 455
Jacek Francuz Avatar asked Apr 07 '11 16:04

Jacek Francuz


People also ask

How do you calculate time zones using latitude and longitude?

We must start by finding the difference in longitude (or degrees) of the two places. We do this by adding the two numbers. Then, divide by the 15 degrees that occurs in one hour and this will give you the time difference between two locations through the International Date Line.

Does longitude dictate time zones?

The rotation of the Earth means that time zones are dictated by the lines of longitude connecting the two poles.


2 Answers

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).

like image 171
Michael Borgwardt Avatar answered Sep 23 '22 07:09

Michael Borgwardt


How exact do your results have to be? If a rough estimate is enough, calculate the offset yourself:

offset = direction * longitude * 24 / 360 

where direction is 1 for east, -1 for west, and longitude is in (-180,180)

like image 28
Christian Stade-Schuldt Avatar answered Sep 23 '22 07:09

Christian Stade-Schuldt