Reputation: 23
I am trying to find all places nearby a certain location in lat_lng. However I get an error when searching for a lat_lng instead of a location (location='location'). I've got a key for the Google places API Web Service and Google Maps Geocoding API. Accoring to https://github.com/slimkrazy/python-google-places this should be enough.
This is my code and my error message:
YOUR_API_KEY = 'API_KEY'
google_places = GooglePlaces(YOUR_API_KEY)
query_result = google_places.nearby_search(
lat_lng='52.0737017, 5.0944107999999915',
radius=100,
types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])
for place in query_result.places:
place.get_details()
print '%s %s %s' % (place.name, place.geo_location, place.types)
Error message:
File "C:\Python27\lib\site-packages\googleplaces\__init__.py", line 281, in nearby_search
lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
File "C:\Python27\lib\site-packages\googleplaces\__init__.py", line 590, in _generate_lat_lng_string
else geocode_location(location=location, api_key=self.api_key))
TypeError: format requires a mapping
Anyone who knows how to fix this problem?
Upvotes: 2
Views: 3983
Reputation: 1338
From the github you provided, the reference section states the lat_lng parameter is of type dict:
lat_lng -- A dict containing the following keys: lat, lng (default None)
Do the following instead:
query_result = google_places.nearby_search(
lat_lng={'lat': 52.0737017, 'lng': 5.0944107999999915},
radius=100,
types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])
To see the query_result, simply do:
query_result.raw_response
Upvotes: 2