Create locationdata.py

This commit is contained in:
SpudGunMan
2024-06-19 15:17:40 -07:00
parent 277c1a8a6b
commit 91467ae86a
+23
View File
@@ -0,0 +1,23 @@
# 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):
# initialize Nominatim API
geolocator = Nominatim(user_agent="geoapiExercises")
location = geolocator.reverse(lat+","+lon)
address = location.raw['address']
# traverse the data
city = address.get('city', '')
state = address.get('state', '')
country = address.get('country', '')
zipcode = address.get('postcode')
print('City : ', city)
print('State : ', state)
print('Country : ', country)
print('Zip Code : ', zipcode)
return location