Is there a Javascript library to go from geopoint and time to timezone?
Question by Luke Hoersten
I’m looking for a Javascript library that can take a geopoint and date and return the timezone. The date is used as input in order to determine the daylight savings time status for that date and location.
I’ve seen there are services which make this information available:
- http://www.earthtools.org/webservices.htm#timezone
- http://www.geonames.org/export/web-services.html#timezone
The information is mostly static, though, so I’d like to not have to depend on external services and am therefore looking for a library. Here’s an example of how I’d like it to work:
tz = geodate.timezone(someFutureDate, lat, lng) => TimeZoneObject
tz.abbr() => "CST"
Answer by Starx
Finding the time zone based on the latitude and longitude has been previously asked on this community. Check
Quoting an answer from Michael
- 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
Now, answering the JavaScript part, JS alone cannot perform such queries as it runs on Client’s Machine. SO either you have to create an API to query the results or send AJAX request to a server page returning you the results.
Sending AJAX request would be a lot better and easier.