I am trying to get city and country names with geopy.
Normally this is how you can get city and country using geopy.
from geopy.geocoders import Nominatim
geolocator = Nominatim(timeout=3)
geolocator.reverse('52.5094982,13.3765983')
loc = location.raw
loc_dict = location.raw
print(loc_dict['address'])
and this is the output:
{'suburb': 'Tiergarten', 'country_code': 'de', 'country': 'Deutschland', 'postcode': '10117', 'attraction': 'Potsdamer Platz', 'road': 'Potsdamer Platz', 'city': 'Berlin', 'city_district': 'Mitte', 'state': 'Berlin'}
My problem is that geopy returns city and country names in their country language, for example:
city: Berlin, country: Deutschland
city: København, country: Danmark
city: București, country: România
i want them like this:
city: Berlin, country: Germany
city: Copenhagen, country: Denmark
city: Bucharest, country: Romania
Is it possible to get them in english as i want? or convert them somehow? I am using all countries and cities arround the world.
adding language in reverse()
function should solve your problem:
geolocator.reverse(location, language='en')