Parse gmaps links containing /place

main
Bob Mottram 2025-04-25 19:22:05 +01:00
parent c4c86fdb13
commit bd9602f0d5
1 changed files with 20 additions and 12 deletions

16
maps.py
View File

@ -332,20 +332,28 @@ def _geocoords_from_gmaps_link(url: str) -> (int, float, float):
if '/maps/' not in url: if '/maps/' not in url:
return None, None, None return None, None, None
coords_str = url.split('/maps', 1)[1] coords_str = url.split('/maps', 1)[1]
if '/@' not in coords_str: if '/@' not in coords_str and '/maps/place/' not in url:
return None, None, None return None, None, None
if '/@' in coords_str:
coords_str = coords_str.split('/@', 1)[1] coords_str = coords_str.split('/@', 1)[1]
if 'z' not in coords_str: else:
return None, None, None coords_str = coords_str.split('/maps/place/', 1)[1]
# NOTE: zoom may have been replaced by metres elevation
zoom_exists = False
if 'z' in coords_str:
coords_str = coords_str.split('z', 1)[0] coords_str = coords_str.split('z', 1)[0]
zoom_exists = True
if ',' not in coords_str: if ',' not in coords_str:
return None, None, None return None, None, None
coords = coords_str.split(',') coords = coords_str.split(',')
if len(coords) != 3: if len(coords) not in (2, 3):
return None, None, None return None, None, None
zoom = '100'
if zoom_exists:
zoom = coords[2] zoom = coords[2]
if not zoom.isdigit(): if not zoom.isdigit():
if is_float(str(zoom)): if is_float(str(zoom)):