属于某个位置的国家(python)?

时间:2017-08-17 07:21:22

标签: python location geopy

通过

Given the lat/long coordinates, how can we find out the city/country?

我试图从坐标中获取信息,并且它正常工作,正如Farsheed在python中写道的那样。但是,我可以只将国家作为答案,是否存在赋予“位置”变量的属性?

1 个答案:

答案 0 :(得分:-1)

>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim(user_agent="specify_your_app_name_here")
>>> location = geolocator.reverse("52.509669, 13.376294")
>>> print(location.address)
Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
>>> print((location.latitude, location.longitude))
(52.5094982, 13.3765983)
>>> print(location.raw)
{'place_id': '654513', 'osm_type': 'node', ...}