internal.geolocation.location
Location translation.
1"""Location translation.""" 2 3from geopy import Location # type: ignore[import-untyped] 4from geopy.geocoders import Nominatim # type: ignore[import-untyped] 5 6from .types import LocationModel 7 8 9def get_location(address: str) -> LocationModel: 10 """Coordinates from Address. 11 12 Args: 13 address: real address 14 15 Returns: 16 coordinates of the address (None, None if failed) 17 """ 18 try: 19 nom = Nominatim(user_agent="hail mary", timeout=10) 20 loc = nom.geocode(address) 21 if not loc or type(loc) is not Location: 22 return LocationModel(lat=None, lon=None) 23 return LocationModel(lat=loc.latitude, lon=loc.longitude) 24 except Exception: 25 return LocationModel(lat=None, lon=None)
10def get_location(address: str) -> LocationModel: 11 """Coordinates from Address. 12 13 Args: 14 address: real address 15 16 Returns: 17 coordinates of the address (None, None if failed) 18 """ 19 try: 20 nom = Nominatim(user_agent="hail mary", timeout=10) 21 loc = nom.geocode(address) 22 if not loc or type(loc) is not Location: 23 return LocationModel(lat=None, lon=None) 24 return LocationModel(lat=loc.latitude, lon=loc.longitude) 25 except Exception: 26 return LocationModel(lat=None, lon=None)
Coordinates from Address.
Arguments:
- address: real address
Returns:
coordinates of the address (None, None if failed)