I have created a function which grabs info about a coordinate using the OSM API. It works fine when there is only 1 lat and lng pair like below:
import pandas as pd
import urllib.request, json
radius = 1000
latitude = -33.8737909
longitude = 151.2055035
def get_results(latitude,longitude):
overpass_url = "http://overpass-api.de/api/interpreter"
overpass_query = '\n[out:json];\n(node["public_transport"](around:{0},{1},{2});\n way["public_transport"](around:{0},{1},{2});\n rel["public_transport"](around:{0},{1},{2});\n);\nout center;\n'.format(radius,latitude,longitude)
response = requests.get(overpass_url,params={'data': overpass_query})
data = response.json()
output = {
"public_transport":[tags['tags'].get('name') for tags in data['elements']]
}
return output
results =[]
for address in addresses:
geocode_result = get_results(latitude,longitude)
results.append(geocode_result)
print(results)
The problem arises when I need to run the above code for multiple lat and lng pairs and append all the results together. For the sake of simplicity, let's say I have a list of two pairs of lat and lng values:
latitude = [-33.8737909, 47.36865]
longitude = [151.2055035, 8.539182]
The function I wrote no longer works. I'm baffled as to why, I suspect it has to do with how I've listed the lng and lat values? Perhaps something else?
Any help appreciated.