mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-03-28 17:32:36 +01:00
28 lines
877 B
Python
28 lines
877 B
Python
# helper functions to use location data
|
|
# K7MHI Kelly Keeton 2024
|
|
|
|
from geopy.geocoders import Nominatim # pip install geopy
|
|
|
|
def where_am_i(lat=0, lon=0):
|
|
whereIam = ""
|
|
# initialize Nominatim API
|
|
geolocator = Nominatim(user_agent="mesh-bot")
|
|
|
|
location = geolocator.reverse(lat+","+lon)
|
|
address = location.raw['address']
|
|
if 'house_number' in address:
|
|
whereIam += address['house_number'] + " "
|
|
if 'road' in address:
|
|
whereIam += address['road'] + ", "
|
|
if 'city' in address:
|
|
whereIam += address['city'] + ", "
|
|
if 'state' in address:
|
|
whereIam += address['state'] + " "
|
|
if 'postcode' in address:
|
|
whereIam += address['postcode']
|
|
if 'county' in address:
|
|
whereIam += " " + address['county']
|
|
if 'country' in address:
|
|
whereIam += " " + address['country']
|
|
|
|
return whereIam |