Is there any library (or even better, web service) available which can convert from a latitude/longitude into a time zone?
2 Answers
I've written a small Java class to do this, with the data structure embedded in the code. If you want to avoid using a web service, and accuracy of 2km is good enough, and you're happy to assume that timezone boundaries don't change, then it could help.
-
-
1
Here are some that I found that you can try for your project.
Library
Timezone
A simple way to get accurate current and historical timezone information based on zone or latitude and longitude coordinates. This gem uses the tz database for historical timezone information. It also uses the geonames API for timezone latitude and longitude lookup.
This is an API for Ruby projects. I haven't try it, since I used web services from Google Time API or TimeZoneDB (see bellow for more detail on TimeZoneDB) for my own projects.
For other programming languages you can always search GitHub.com.
Web Service
TimeZoneDB
TimezoneDb provides simple RESTful interface API and returns structured XML or JSON responses. Our API converts latitude & longitude to time zone data. You also able to retrieve time zone information for a specific zone. You need to register a free API key to start using our services.
You can use TimeZoneDB API to get time zone information on geographical point, i.e. longitude/latitude or time zone name. Before you can use it on your own project, you will need to sign up for the free service and get an API key.
Given the longitude/latitude pair or time zone name, the API will response with:
- Error message, if any occured.
- Status:
OK
orFail
. - GMT offset based on UTC time
- Country code (e.g.
ID
) - Time zone name (e.g.
Asia/Jakarta
) - Time zone abbreviation
- Unix Timestamp
I personally used TimeZoneDB and cached the response on my back-end server to be used by a mobile client application.