Batch requests for Google Places (Javascript v3)

大兔子大兔子 提交于 2019-12-24 22:32:09

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17778437/batch-requests-for-google-places-javascript-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!