3

The following code is from the package geopy for python (https://geopy.readthedocs.org/en/1.10.0/):

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

It takes as input a lat and lon and returns the address. However in my code I have recieved a lat and lon of an image using the flikcr API as follows

photo_list = flickr.photos.search(api_key=api_key, accuracy = 15, has_geo=1, per_page = 100, extras = 'tags, url_s')

I then want to do the following:

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

The lat and lon are being obtained fine. If I try to print them each time the print perfectly. Also I have I have imported geopy and everything relevant at the top of my program. However I am getting the error:

ValueError: Must be a coordinate pair or Point.

I am new to Python so I would really appreciate any help! How would I be able to input the lat and lon successfully each time.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
RyanKilkelly
  • 279
  • 1
  • 4
  • 15

0 Answers0