以下代码来自python(https://geopy.readthedocs.org/en/1.10.0/)的包geopy:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.reverse("52.509669, 13.376294")
print(location.address)
>>>Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
输入lat和lon并返回地址。然而,在我的代码中,我使用flikcr API接收了一个图像的lat和lon,如下所示
photo_list = flickr.photos.search(api_key=api_key, accuracy = 15, has_geo=1, per_page = 100, extras = 'tags, url_s')
然后我想做以下事情:
for photo in photo_list[0]:
photo_location = flickr.photos_geo_getLocation(photo_id=photo.attrib['id'])
lat = photo_location[0][0].attrib['latitude']
lon = photo_location[0][0].attrib['longitude']
geolocator = Nominatim()
location = geolocator.reverse(lat, lon)
print(location.address)
>>>Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
纬度和经度都很好。如果我每次打印完美时都尝试打印它们。此外,我已经导入了geopy以及与我的程序顶部相关的所有内容。但是我收到了错误:
ValueError:必须是坐标对或Point。
我是Python的新手,所以我真的很感激任何帮助!我怎样才能每次成功输入lat和lon。