【问题标题】:python geopy get city and countrypython geopy获取城市和国家
【发布时间】:2017-10-18 11:52:03
【问题描述】:

我正在尝试使用 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

是否可以按照我的意愿使用英语?或以某种方式转换它们?我正在使用世界上所有国家和城市。

【问题讨论】:

    标签: python geopy


    【解决方案1】:

    reverse() 函数中添加语言应该可以解决您的问题:

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

    【讨论】:

      猜你喜欢
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2016-12-17
      • 2013-01-12
      • 2013-11-13
      相关资源
      最近更新 更多