Parsing google maps location links

merge-requests/30/head
Bob Mottram 2022-06-05 13:15:02 +01:00
parent fd7781d623
commit e9a0b6b151
1 changed files with 10 additions and 3 deletions

13
maps.py
View File

@ -46,17 +46,24 @@ def _geocoords_from_osm_link(url: str, osm_domain: str) -> (int, float, float):
def _geocoords_from_gmaps_link(url: str) -> (int, float, float):
"""Returns geocoordinates from a Gmaps link
"""
if '/maps/@' not in url:
if '/maps/' not in url:
return None, None, None
coords_str = url.split('/maps', 1)[1]
if '/@' not in coords_str:
return None, None, None
coords_str = url.split('/maps/@')[1]
coords_str = coords_str.split('/@', 1)[1]
if 'z' not in coords_str:
return None, None, None
coords_str = coords_str.split('z', 1)[0]
if ',' not in coords_str:
return None, None, None
coords = coords_str.split(',')
if len(coords) != 3:
return None, None, None
zoom = coords[2].replace('z', '')
zoom = coords[2]
if not zoom.isdigit():
return None, None, None
latitude = coords[0]