Skip to content

lat_lon

zeus.utils.lat_lon

Function for getting latitude and longitude.

get_ip_lat_long

get_ip_lat_long()

Retrieve the latitude and longitude of the current IP position.

Source code in zeus/utils/lat_lon.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def get_ip_lat_long() -> tuple[float, float]:
    """Retrieve the latitude and longitude of the current IP position."""
    try:
        ip_url = "http://ipinfo.io/json"
        resp = requests.get(ip_url)
        loc = resp.json()["loc"]
        lat, long = map(float, loc.split(","))
        logger.info("Retrieved latitude and longitude: %s, %s", lat, long)
        return lat, long
    except requests.exceptions.RequestException as e:
        logger.exception(
            "Failed to retrieve current latitude and longitude of IP: %s", e
        )
        raise