Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next page function not working #115

Open
nicolasraj opened this issue Apr 4, 2018 · 4 comments
Open

Next page function not working #115

nicolasraj opened this issue Apr 4, 2018 · 4 comments

Comments

@nicolasraj
Copy link

I can only get 20 results per search

@01ghost13
Copy link

Same here

@slimkrazy
Copy link
Owner

I'll get around to taking a look at this issue over the weekend.

@01ghost13
Copy link

01ghost13 commented Apr 10, 2018

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)

@sheisunique
Copy link

Have you solved it yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants