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

Rate limiting not working correctly #338

Closed
dvankley opened this issue Aug 18, 2017 · 2 comments
Closed

Rate limiting not working correctly #338

dvankley opened this issue Aug 18, 2017 · 2 comments

Comments

@dvankley
Copy link
Contributor

dvankley commented Aug 18, 2017

I've been trying out the library for making nearby search requests lately and overall it works great. I am having a timing issue that I haven't been able to clear up, namely that I keep getting InvalidRequestExceptions on my nearbySearchNextPage() calls following my initial nearbySearchQuery() call. If I add a Thread.sleep() before the nearbySearchQuery call then I don't see the error, which is what makes me think it's a rate limiting issue of some kind. I'm on version 0.2.1

It doesn't seem to be on Google's end because I don't see any errors in the API console.

Manually setting the rate limit very low or high with queryRateLimit() also doesn't help.

Any hints on what I'm doing wrong would be helpful. Thanks!

Sample code:

    public static void main( String[] args )
    {
        try {
            String apiKey = "Insert API Key here";

            Double homeLat = 33.7606946;
            Double homeLong = -84.3907441;

            GeoApiContext.Builder builder = new GeoApiContext.Builder();
            GeoApiContext context = builder
                    .apiKey(apiKey)
                    .build();

            NearbySearchRequest request = PlacesApi.nearbySearchQuery(context, new LatLng(homeLat, homeLong));
            request.radius(5000);
            request.type(PlaceType.RESTAURANT);

            PlacesSearchResponse response = request.await();

            while (response.nextPageToken != null) {
                request = PlacesApi.nearbySearchNextPage(context, response.nextPageToken);
                request.radius(1000);
                request.type(PlaceType.RESTAURANT);
                response = request.await();
            }
        } catch (Exception e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }
@domesticmouse
Copy link
Contributor

Per https://developers.google.com/places/web-service/search#PlaceSearchPaging there is a short delay between the result containing the next_page_token and the page token becoming valid.

@dvankley
Copy link
Contributor Author

Makes sense, thanks. Mind if I add a note to the Readme here to remind users of that?

dvankley pushed a commit to dvankley/google-maps-services-java that referenced this issue Aug 18, 2017
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

2 participants