-1

我想你可以帮我设置这个函数的超时时间。我设置的超时似乎会破坏循环。

window.eqfeed_callback = function(results) {
    for (var i = 0; i < results.features.length; i++) {
        var earthquake = results.features[i];
        var coords = earthquake.geometry.coordinates;
        var latLng = new google.maps.LatLng(coords[1],coords[0]);
        var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            icon: getCircle(earthquake.properties.mag) 
        });
        map.panTo(latLng);
    }
}

已解决:通过定义一个函数来进行变量

window.eqfeed_callback = function(results) {
    for (var i = 0; i < results.features.length; i++) {
       var earthquake = results.features[i];
       var coords = earthquake.geometry.coordinates;
       var latLng = new google.maps.LatLng(coords[1],coords[0]);
       (function(i, earthquake, coords, latLng) {
         setTimeout(function() {
         var marker = new google.maps.Marker({
           position: latLng,
           map: map,
           icon: getCircle(earthquake.properties.mag),
           animation: google.maps.Animation.DROP });
         map.panTo(latLng);
         }, i * 400);
       }(i, earthquake, coords, latLng));

    }
}
4

1 回答 1

0

以下内容对您有用吗?当然,您必须在结果变量中传递有效数据才能使回调执行正常工作。

setTimeout(function() {
    window.eqfeed_callback(results)
}, 4000);
于 2012-12-26T10:51:36.733 回答