gpt4 book ai didi

python geopy 获取城市和国家

转载 作者:行者123 更新时间:2023-12-05 01:44:13 59 4
gpt4 key购买 nike

我正在尝试使用 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() 函数中添加语言应该可以解决您的问题:

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

关于python geopy 获取城市和国家,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46809525/

59 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com