From 91467ae86ab9fa612563f11aea96d3feff66c277 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 15:17:40 -0700 Subject: [PATCH] Create locationdata.py --- locationdata.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 locationdata.py diff --git a/locationdata.py b/locationdata.py new file mode 100644 index 0000000..d7799d9 --- /dev/null +++ b/locationdata.py @@ -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 \ No newline at end of file