October 28, 2012

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:

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

  1. Determine timezone from latitude/longitude without using web services like Geonames.org
  2. Get PHP Timezone Name from Latitude and Longitude? (Similar to 1)

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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!