我正在尝试使用 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'}
Run Code Online (Sandbox Code Playgroud)
我的问题是 geopy 以其国家语言返回城市和国家名称,例如:
city: Berlin, country: Deutschland
city: København, country: Danmark
city: Bucure?ti, country: România
Run Code Online (Sandbox Code Playgroud)
我希望他们像这样:
city: Berlin, country: Germany
city: Copenhagen, country: Denmark
city: Bucharest, country: Romania
Run Code Online (Sandbox Code Playgroud)
是否有可能按照我的意愿用英语获得它们?或以某种方式转换它们?我正在使用世界各地的所有国家和城市。
小智 5
在reverse()函数中添加语言应该可以解决您的问题:
geolocator.reverse(location, language='en')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5823 次 |
| 最近记录: |