pythonjsonfoursquare

Using 'for loop'


How can I use 'for loop' to get multiple values of lng and lat for more than one address?

Here I have only one address. What if I have 13 other addresses and I want all their corresponding [lat, lng] as output. By the way, I have used necessary libraries like 'geopy', etc (not important here I guess)

address = 'Nobels gate 32, N-0268 Oslo'
geolocator = Nominatim(user_agent="foursquare_agent")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
print(latitude, longitude)

59.922816 10.700466

Solution

  • You can loop over the addresses, accessing one address at a time. Here is a pseudocode

    addresses = ['Nobels gate 32, N-0268 Oslo', ....]
    geolocator = Nominatim(user_agent="foursquare_agent")
    for add in addresses:
        location = geolocator.geocode(add)
        latitude = location.latitude
        longitude = location.longitude
        print(latitude, longitude)