python-google-places
python-google-places copied to clipboard
Next page function not working
I can only get 20 results per search
Same here
I'll get around to taking a look at this issue over the weekend.
Hi @slimkrazy i just monkeypatched your function nearby_search
.
It's a bit rough, but works for me.
The problem was in rewriting old params even if pagetoken was enabled. You need only pagetoken and apikey for query.
def nearby_search(self, language=lang.ENGLISH, keyword=None, location=None,
lat_lng=None, name=None, radius=3200, rankby=ranking.PROMINENCE,
sensor=False, type=None, types=[], pagetoken=None):
if location is None and lat_lng is None and pagetoken is None:
raise ValueError('One of location, lat_lng or pagetoken must be passed in.')
if rankby == 'distance':
# As per API docs rankby == distance:
# One or more of keyword, name, or types is required.
if keyword is None and types == [] and name is None:
raise ValueError('When rankby = googleplaces.ranking.DISTANCE, ' +
'name, keyword or types kwargs ' +
'must be specified.')
self._sensor = sensor
if pagetoken is None:
radius = (radius if radius <= GooglePlaces.MAXIMUM_SEARCH_RADIUS
else GooglePlaces.MAXIMUM_SEARCH_RADIUS)
lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
self._request_params = {'location': lat_lng_str}
if rankby == 'prominence':
self._request_params['radius'] = radius
else:
self._request_params['rankby'] = rankby
if type:
self._request_params['type'] = type
elif types:
if len(types) == 1:
self._request_params['type'] = types[0]
elif len(types) > 1:
self._request_params['types'] = '|'.join(types)
if keyword is not None:
self._request_params['keyword'] = keyword
if name is not None:
self._request_params['name'] = name
if language is not None:
self._request_params['language'] = language
self._add_required_param_keys()
url, places_response = _fetch_remote_json(
GooglePlaces.NEARBY_SEARCH_API_URL, self._request_params)
_validate_response(url, places_response)
return GooglePlacesSearchResult(self, places_response)
else:
_request_params = { 'pagetoken': pagetoken }
_request_params['key'] = self.api_key
url, places_response = _fetch_remote_json(
GooglePlaces.NEARBY_SEARCH_API_URL, _request_params)
_validate_response(url, places_response)
return GooglePlacesSearchResult(self, places_response)
Have you solved it yet?