Fix geolocation bug

main
Bob Mottram 2025-07-10 21:11:30 +01:00
parent f52bea9445
commit efd4490101
2 changed files with 18 additions and 1 deletions

10
maps.py
View File

@ -591,7 +591,7 @@ def _geocoords_from_gmaps_link(url: str) -> (int, float, float):
coords = coords_str.split(',') coords = coords_str.split(',')
if len(coords) not in (2, 3): if len(coords) not in (2, 3):
return None, None, None return None, None, None
zoom = '100' zoom = 100
if zoom_exists: if zoom_exists:
zoom = coords[2] zoom = coords[2]
if not zoom.isdigit(): if not zoom.isdigit():
@ -602,6 +602,8 @@ def _geocoords_from_gmaps_link(url: str) -> (int, float, float):
latitude = coords[0] latitude = coords[0]
if not is_float(latitude): if not is_float(latitude):
return None, None, None return None, None, None
if '"' in coords[1]:
coords[1] = coords[1].split('"')[0]
longitude = coords[1] longitude = coords[1]
if not is_float(longitude): if not is_float(longitude):
return None, None, None return None, None, None
@ -639,6 +641,8 @@ def _geocoords_from_bmaps_link(url: str) -> (int, float, float):
if not is_float(latitude): if not is_float(latitude):
return None, None, None return None, None, None
longitude = coords[1] longitude = coords[1]
if '"' in coords[1]:
coords[1] = coords[1].split('"')[0]
if not is_float(longitude): if not is_float(longitude):
return None, None, None return None, None, None
zoom = 17 zoom = 17
@ -685,6 +689,8 @@ def _geocoords_from_waze_link(url: str) -> (int, float, float):
if not is_float(latitude): if not is_float(latitude):
return None, None, None return None, None, None
longitude = coords[1] longitude = coords[1]
if '"' in coords[1]:
coords[1] = coords[1].split('"')[0]
if not is_float(longitude): if not is_float(longitude):
return None, None, None return None, None, None
zoom = 17 zoom = 17
@ -723,6 +729,8 @@ def _geocoords_from_wego_link(url: str) -> (int, float, float):
if not is_float(latitude): if not is_float(latitude):
return None, None, None return None, None, None
longitude = coords[1] longitude = coords[1]
if '"' in coords[1]:
coords[1] = coords[1].split('"')[0]
if not is_float(longitude): if not is_float(longitude):
return None, None, None return None, None, None
zoom = coords[2] zoom = coords[2]

View File

@ -8336,6 +8336,15 @@ def _test_hashtag_maps():
assert longitude assert longitude
assert int(longitude * 1000) == 135502 assert int(longitude * 1000) == 135502
link = "<a href=\"https://www.google.com/maps/place/36.82,-3.15\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" translate=\"no\"><span class=\"invisible\">https://www.</span><span class=\"ellipsis\">google.com/maps/place/36.82</span><span class=\"invisible\">3,-3.15</span></a>"
zoom, latitude, longitude = \
geocoords_from_map_link(link, 'openstreetmap.org', session)
assert zoom == 100
assert latitude
assert int(latitude * 1000) == 36820
assert longitude
assert int(longitude * 1000) == -3150
def _test_uninvert(): def _test_uninvert():
print('test_uninvert') print('test_uninvert')