I am trying to print the specific country code from a lat/long pair using GeoPy. It can return the address, latitude, longitude, or the entire JSON as a dict, but not individual components.
Is there a way I can access only the country portion and return that? Here is the code I have working that outputs the raw response from geolocator:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
Lat = input('Lat: ')
Long = input('Long: ')
location = geolocator.reverse([Lat, Long])
print(location.raw)
Here is the output I receive:
{'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright', 'address': {'house_number': '1600', 'city': 'Washington', 'country_code': 'us', 'postcode': '20500', 'attraction': 'White House', 'neighbourhood': 'Monumental Core', 'country': 'United States of America', 'state': 'District of Columbia', 'pedestrian': 'Pennsylvania Avenue Northwest'}, 'display_name': 'White House, 1600, Pennsylvania Avenue Northwest, Monumental Core, Washington, District of Columbia, 20500, United States of America', 'lat': '38.8976989', 'boundingbox': ['38.8974898', '38.897911', '-77.0368539', '-77.0362521'], 'osm_id': '238241022', 'place_id': '2611224231', 'osm_type': 'way', 'lon': '-77.036553192281'}