setInterval javascript似乎没有很好地响应
setInterval javascript does not seem to respond well
小摘要。由于地理编码不允许大量同时请求,并且我必须在我的谷歌地图上显示超过 11 个标记,我想我会使用某种间隔来绕过同时请求限制。
我想在这里我会使用 javascript 中的 setInterval 函数。
这是我的代码
function timeHackGeocode(location, name, contract, vestigingID)
{
setInterval(codeAddress(location, name, contract, vestigingID), 1000);
}
function collectingData() {
@foreach (var item in Model) {
@:timeHackGeocode("@item.StraatVestiging" + " " + "@item.nr" + "," + "@item.location","@item.name","@item.Contract", "@item.id");
}
}
function codeAddress(location, name, contract, vestigingID) {
var address = location;
var image;
var zoomlevel;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var infoboxPos = results[0].geometry.location;
var image = new google.maps.MarkerImage(returnImage(contract),
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(30, 42),
// The origin for this image is 0,0.
new google.maps.Point(40,45),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32));
var marker = createMarkers(results[0].geometry.location, contract)
google.maps.event.addListener(marker, 'mouseover', function() {
infobox.open(map, marker);
infobox.setOptions(infoboxOptions(boxText(name, contract, vestigingID), infoboxPos));
});
} else {
// alert("Geocode was not successful for the following reason: " + status);
}
});
}
不幸的是,这似乎不起作用,我尝试了各种不同的设置。https://developer.mozilla.org/en/DOM/window.setInterval
有人知道发生了什么吗?
附言。我将在未来通过已经拥有纬度和经度来更改此黑客,但现在我希望让它工作。
建议非常感谢。
如果您需要将参数传递给回调函数,但需要它在 Internet Explorer 中工作,而 Internet Explorer 不支持使用 setInterval() 发送其他参数,请使用匿名函数调用回调。
var time =setInterval(function(){ codeAddress(location, name, contract, vestigingID); },1000);
绕过速率限制是可能的。请参阅谷歌地图V3:仅显示一些标记,这是完全相同的问题。
这是该答案的相关部分:
您需要减慢请求速度。当您提交更多请求时,您可能不得不进一步减慢请求速度以满足地理编码器的要求。我在 http://acleach.me.uk/gmaps/v3/plotaddresses.htm 上制作了一个版本 3 示例(来自一个著名的版本 2 示例)——您可以看到它以请求之间的 100 毫秒延迟开始,但在 20 次迭代后需要减慢到 150 毫秒左右。
相关文章:
- 我如何才能让CasperJS和PhantomJS在约塞米蒂玩得很好
- 在Javascript中使用全局变量作为缓存是很好的
- 我在下拉列表中尝试了下一个和前五年的html代码.接下来的5年我都过得很好.我怎样才能拿到之前的5年
- JavaScript中的OOP太令人困惑了,ES6很棒,但没有得到很好的支持,该怎么办
- "此网站似乎使用滚动链接定位效果.这可能不能很好地与异步平移一起工作;
- html5:一个很好的加载方法
- mootools 1.4.2和angular 1.3在ie8中配合得很好
- Javascript是一个很好的日期选择器和时间选择器库
- 使用JavaScript验证用户交互/输入-这是一种很好的方法
- unbind().click(function(){..})是一种很好的做法
- Chrome,Safari在从本地存储读取时挂起,而Firefox很好
- JQuery在Chrome中不起作用,但Firefox很好
- 这是一个很好的例子,显示了 JavaScript 中的 OOP 和过程编程之间的区别
- Javascript表排序工作得很好,但对所有索引进行迭代会得到不同的结果
- setInterval javascript似乎没有很好地响应
- 代码不'当上传到服务器[HTML,CSS,JS][错误:服务器停止响应]时,不会表现得很好
- Ajax - JSON响应不能很好地读取id数组
- 如何显示图像在Froala编辑器ajax响应后,在Codeigniter一个很好的链接
- 响应式设计+ jQuery很好,除了Firefox
- 可触摸视图响应本机响应速度不是很好