Improve coordinate timezone resolution with timezonefinder fallbacks
This commit is contained in:
parent
1ee1f38a99
commit
38cf270307
1 changed files with 8 additions and 2 deletions
10
web_view.py
10
web_view.py
|
|
@ -797,8 +797,14 @@ def _timezone_from_coordinates(latitude: float, longitude: float) -> str | None:
|
||||||
if timezone_finder is None:
|
if timezone_finder is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
tz_name = timezone_finder.timezone_at(lng=longitude, lat=latitude)
|
for method_name in ("timezone_at", "certain_timezone_at", "closest_timezone_at"):
|
||||||
return tz_name if isinstance(tz_name, str) else None
|
finder_method = getattr(timezone_finder, method_name, None)
|
||||||
|
if not callable(finder_method):
|
||||||
|
continue
|
||||||
|
tz_name = finder_method(lng=longitude, lat=latitude)
|
||||||
|
if isinstance(tz_name, str):
|
||||||
|
return tz_name
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=1)
|
@functools.lru_cache(maxsize=1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue