带有新API密钥的Google Places Library OVER_QUERY_LMIT
Google Places Library OVER_QUERY_LIMIT with new API key
我正在javascript应用程序中使用Places库。当我使用service.nearbySearch()
方法查找附近的地方时,它工作得很好。当我发出service.getDetails()
请求时,我会得到每个请求的OVER_QUERY_LIMIT
状态。在我的开发人员控制台中,我可以跟踪对Google Maps JavaScript API v3的每个请求,但我不会从API地方得到任何结果。
以下是一些代码:
// How I load the library
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=API_KEY"></script>
// My places request
var places = new google.maps.places.PlacesService(map);
var location = new google.maps.LatLng(lat, lng);
var request = {
location: location,
radius: radius,
types: [type]
};
places.nearbySearch(request, function(results, status, pagination) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
// Get the details for each place
var detailsRequest = { placeId: results[i].id }
places.getDetails(detailsRequest, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log('PLACE', place)
} else {
console.log('STATUS', status)
}
})
};
}
有什么想法吗?
答案是我请求.getDetails()
方法的速度太快。文档。
我迭代了几十个位置,请求太多太快。通常情况下,在OVER_QUERY_LIMIT
错误之前,我只会得到60+个结果中的前10个或12个。
我将对.getDetails()
的调用移动到标记的单击事件。这样一次只发送一个请求。
也遇到了同样的问题。似乎你有一个9或10个请求池,你可以耗尽,然后每1秒就可以获得一个额外请求的余量。
有人说API的服务器端版本每秒允许50个请求,所以我猜谷歌正在努力防止客户端实例过载,这是有道理的。
对我来说,当getDetails结果/s出现时,只需要UI显示微调器就足够了。所以我只是在前9或10个请求之后抑制了请求,就像这样:
nearbySearchCallback: function (places, status) {
var that = this;
if (status === window.google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < places.length; i++) {
// You seem to have a pool of 9 or 10 requests to exhaust,
// then you get another request every second therein.
(function (i) {
setTimeout(function () {
service.getDetails({ placeId: places[i].place_id }, that.getDetailsCallback);
}, i < 9 ? 0 : 1000 * i);
})(i);
}
}
},
getDetailsCallback: function (place, status) { /* ... */ }
相关文章:
- GWT (or javascript) library for couchDB
- Javascript Audio Library
- Babel编译错误:找不到模块核心js/library/fn/get迭代器
- PHPChart library - Scriptpath
- 带有新API密钥的Google Places Library OVER_QUERY_LMIT
- dropable的Over事件是't工作正常,在可拖动对象被拖放到贪婪的可拖动对象上并再次拖动后
- Iterate over SQLOBJECT -WEBSQL
- Javascript SVG viewer library
- JavaScript iCal Library
- Google Places Library Replacement for google.maps.LocalSearc
- jquery image-over不起作用
- chap链接library-network-如何获取表行id
- 如何在谷歌浏览器中使用step-int和step-over'用于调试Java脚本的Web检查器
- Javascript Forge Crypto Library:重新创建公钥和私钥以供以后重用
- JavaScript library development
- splat over JavaScript 对象(带有 new)
- Protobuf over zeromq/zwssock to JSMQ/ProtoBuf.js 消息未完全接收
- Javascript loop over getElementsByClassName
- AngularJS and sidr library
- Custom clipping path over HTML <div>