2017-10-18 179 views
-1

我想要得到城市和國家的名字geopy。蟒蛇geopy得到城市和國家

通常情況下,您可以使用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'} 

我的問題是geopy在他們國家的語言返回城市和國家的名稱,例如:

city: Berlin, country: Deutschland 
city: København, country: Danmark 
city: București, country: România 

我想他們是這樣的:

city: Berlin, country: Germany 
city: Copenhagen, country: Denmark 
city: Bucharest, country: Romania 

是否有可能得到他們用英文,因爲我想要?或以某種方式轉換它們?我正在使用世界各地的所有國家和城市。在reverse()功能

回答

1

添加語言應該解決您的問題:

geolocator.reverse(location, language='en') 
+0

是的,它做到了,我還是選你的答案接受:) –