Question

Is there any library (or even better, web service) available which can convert from a latitude/longitude into a time zone?

Was it helpful?

Solution

I looked fairly deeply into this question for a project I am working on. GeoNames.org and EarthTools.com are both good options for many situations but with the following serious flaws:

  • GeoNames.org finds the time zone by searching for the nearest point in their database that contains a time zone field. This often leads to the wrong result near borders. It is also painfully slow, leading to query times on the order of a couple seconds per request. It also doesn't return a valid time zone if there is no item in their database near the query point. GeoNames also restricts the number of queries that can be made per day, making bulk operations difficult.
  • EarthTools.org uses a map and is able to return queries quickly, but it doesn't take into account daylight savings time for most locations, and it returns a raw offset rather than a time zone ID (i.e., they return "GMT-7" instead of "America/Chicago"). Also, I just looked at their page while preparing this post and Google Chrome warned about malware on their site. That is new to me and it may change, but is obviously a cause for concern.

These flaws meant that these existing tools were not suitable for my needs so I rolled my own solution and have published it for general use. You can find it here:

http://www.askgeo.com/

AskGeo is based on a time zone map of the world, so it returns a valid time zone for every valid latitude and longitude. It returns the standard time zone ID (e.g., "America/Los_Angeles") used on Linux and most other operating systems and programming frameworks. It also returns the current offset, taking full account of daylight savings time.

It is extremely easy to use and usage is documented on the main page of the site. The API supports batch queries, so if you need to do a lot of look-ups, please use the batch interface rather than bog down our servers with serial requests. The bulk queries are also much faster, so everybody wins.

When we first launched this, we built it on Google App Engine (GAE) and made it free to all users. This was possible because GAE's prices were so low at that time. Since then, our server load has increased substantially and GAE's prices went way up. Both factors combined led us to switch to Amazon Web Services for hosting and to start charging for commercial use, while keeping the service free for non-profit, non-commercial open source projects, and researchers. For commercial users, we provide 1000 free queries to let potential customers evaluate the API to make sure it meets their needs. See the web site for pricing and terms.

The underlying library was written in Java and due to popular demand, we also released the library under a commercial license. Full documentation of the library and pricing details are on the web site.

I hope this is useful. It certainly was useful for the project I was working on.

OTHER TIPS

Take a look at Geonames.org

It's a free webservice that allow you to get a lot of informations from a long/lat

They also provide a free (and open source) Java Client for GeoNames Webservices library (library for other language also provided: ruby, python, perl, lisp...)

Here's some info you can get from long/lat: (complete list of webservices here)

  • Find nearest Address
  • Find nearest Intersection
  • Find nearby Streets
  • Elevation
  • Timezone

Timezones are now available via Google API

https://developers.google.com/maps/documentation/timezone/

The Yahoo places API provides timezone information via reverse geolocation.

Check it out.

http://developer.yahoo.com/geo/placefinder/guide/requests.html

How much accuracy do you need? Dividing the longitude by 15 would almost be right :p

Project dead :-/

These look pretty promising-

Archive link:

https://web.archive.org/web/20150503145203/http://www.earthtools.org/webservices.htm

Eric Muller has made shapefile maps for the timezones of the tz (Olson) database. A few minor caveats, though:

  1. The boundaries used are often unofficial.
  2. It isn't updated as regularly as the tz database itself, so some newly-formed or -adjusted zones may be missing.

Those aside, however, it seems to be very accurate for most purposes.

DRT Engine takes a latitude, longitude and local datetime and returns a timezone offset. This can be used to establish the timezone of a particular location at a future date.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top