Reputation: 1
I was doing a project exploring Los Angeles data with Foursquare API. However, I got an error 'groups'and 'meta' the error details showed 'invalid geo coordinates'.
How can i proceed from the error? Is there a way to ignore this error and move on? Please see below for my code (the formulas all comes from my lab class. The only change is'Los Angeles' coordinates input, and sadly it no longer works)
address = 'Los Angeles, CA'
geolocator = Nominatim(user_agent="la_explorer")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
print('The geograpical coordinate of Los Angeles are {}, {}.'.format(latitude, longitude))
after the run i got:The geograpical coordinate of Los Angeles are 34.0536909, -118.2427666.
def getNearbyVenues(names, latitudes, longitudes, radius=600, LIMIT=100):
venues_list=[]
for name, lat, lng in zip(names, latitudes, longitudes):
print(name)
# create the API request URL
url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(
CLIENT_ID,
CLIENT_SECRET,
VERSION,
lat,
lng,
radius,
LIMIT)
# make the GET request
results = requests.get(url).json()["response"]['groups'][0]['items']
# return only relevant information for each nearby venue
venues_list.append([(
name,
lat,
lng,
v['venue']['name'],
v['venue']['location']['lat'],
v['venue']['location']['lng'],
v['venue']['categories'][0]['name']) for v in results])
nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])
nearby_venues.columns = ['Neighborhood',
'Neighborhood Latitude',
'Neighborhood Longitude',
'Venue',
'Venue Latitude',
'Venue Longitude',
'Venue Category']
return(nearby_venues)
print(results)
after the run i got:
{'meta': {'code': 400, 'errorType': 'param_error', 'errorDetail': 'Invalid geo coordinates (-118.169810,34.497355)', 'requestId': '5ec0766ac8cff2001ce42bf2'}, 'response': {}}
Please help! Thank you so much!
Upvotes: 0
Views: 298
Reputation: 1826
Actual coordinates of Your address is 34.0536909, -118.2427666
it seems latitude and longitude are swapped change it
Upvotes: 0
Reputation: 7451
(-118.169810,34.497355) is invalid geo coordinates. latitude and longitude are in reverse order. Try (34.497355,-118.169810)
Upvotes: 1