简体   繁体   中英

Batch requests for Google Places (Javascript v3)

Is there a way to batch requests for the Places Library in JavaScript? I've seen this page , so I've gathered it's possible, at least, I'm just not sure how it'd work with Places API.

I need to run a request for every place I find on google maps (this leads to a lot of OVER_QUERY_LIMIT exceptions). I've given thought to queuing the requests and running them a second apart, but if a user gets several hundred places queued up, a fair amount of results are going to go missing if the user closes the page preemptively.

I'd rather not defer processing to the server in this case if possible.

Well, here was my solution in Javascript:

var intId = setInterval(function() {
    try {
        service.getDetails(place, getMorePlaceDetails);
        clearInterval(intId);
    } catch(e) {
        console.info("Could not get detailed information about "+place.name+"; retrying in 3...");
    }
}, 3000);

Every place that threw an exception when it tried to get more details was retried in 3 seconds.

Batching is supported for some of Google's, and is really easily achieved with the API client library (at least in PHP). Unfortunately, Places is not one of the supported APIs.

But that doesn't really matter in your case because even if you batch them, they still all count toward your query limit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM