This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Is there a way to get a timezone from a city or town via the API?

1

Is there an API endpoint that would retrieve a timezone passing the name of a city or town as a parameter? While not all cities or towns have unique names (a quick test would be to google for "list of cities with name Paris"), depending on the API call result, one could easily work around that.

asked 11 Feb '20, 11:10

gtludwig's gravatar image

gtludwig
26113
accept rate: 0%


2 Answers:

1

Usually it's a two step process: convert address to coordinates (geocoding), lookup timezone using the coordinates. While https://nominatim.openstreetmap.org/ can do the first part it doesn't have the data for the timezone. Well, technically it can be extracted from OSM data but it's complex and hard to maintain. https://github.com/evansiroky/timezone-boundary-builder does that. Then you only have the timezone name, the calculation what time it is in the city is also complex because you need to know if there's daylight saving time, whose rules differ from country to country. Not all APIs can handle coordinates in the ocean (https://en.wikipedia.org/wiki/Nautical_time).

There are a couple of businesses that offer timezone API, check https://stadiamaps.com/products/geospatial-apis/ , https://opencagedata.com/ , https://timezonedb.com/references/get-time-zone , https://www.timeanddate.com/services/api/

disclaimer: I work for opencagedata

answered 14 Feb '20, 22:19

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

0

No (if you mean an API provided by the OSMF or any of the "core" OSM services).

answered 13 Feb '20, 19:23

SimonPoole's gravatar image

SimonPoole ♦
44.7k13326701
accept rate: 18%

Source code available on GitHub .