tzwhere (also referred to as pytzwhere) is a Python library designed to look up the timezone for a given latitude and longitude entirely offline. The current version, 3.0.3, released in August 2017, focuses on improving how it handles 'holes' within timezone polygons. It is a mature library, but its data sources and development are not as current as some alternatives.
pip install tzwhereVerified import paths — ran on the pinned version, not inferred.
Initialize the tzwhere object once to load timezone data. Then, use the `tzNameAt` method with latitude and longitude to find the corresponding IANA timezone name. The `forceTZ=True` parameter can be used to find the closest timezone even if the point falls outside strict polygon boundaries.
Ensure you are importing the `tzwhere` class explicitly and instantiating it with `tz = tzwhere.tzwhere()` as documented in the quickstart.
To get the closest timezone name in such cases, use the `forceTZ=True` parameter: `tz.tzNameAt(latitude, longitude, forceTZ=True)`.
For applications with strict memory or startup performance requirements, consider alternative libraries like `timezonefinder` which are optimized for speed and memory usage, or `geodjango-tzwhere` if using a spatial database.
For the most up-to-date and accurate timezone data, it is recommended to use actively maintained alternatives like `timezonefinder` which regularly updates its data.
Change your import statement to `from tzwhere import tzwhere`. Then you can correctly instantiate the class with `tz = tzwhere()`.
Pass the `forceTZ=True` argument to the `tzNameAt` method to find the closest timezone even if the point is not strictly within a polygon: `tz.tzNameAt(latitude, longitude, forceTZ=True)`.
If high memory usage or slow startup is a critical concern, consider migrating to alternative libraries like `timezonefinder` which offers optimizations for memory and speed, or `geodjango-tzwhere` for database-backed lookups.