2012-04-23 31 views
-1

小概要。由於地理編碼不允許大量的同時請求,我必須在googlemap上顯示多於11個標記,我想我會使用某種間隔來繞過同時請求限制。
我想在這裏我會使用javascript的setInterval函數。setInterval javascript似乎沒有反應良好

這是我的代碼

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

有沒有人有一個想法是怎麼回事?

ps。我將通過已經擁有的經緯度來改變這種黑客行爲,但現在我希望能夠實現這一目標。

建議非常感謝。

+0

您可以張貼在現場的網站或的jsfiddle或東西的鏈接呢?很難爲您的響應調試代碼片段 – 2012-04-23 17:00:44

回答

0

如果你需要一個參數傳遞給你的回調函數,但需要在Internet Explorer,它不支持在使​​用setInterval(發送額外的參數)的工作,使用匿名函數來調用回調函數。

var time =setInterval(function(){ codeAddress(location, name, contract, vestigingID); },1000); 
+0

ty,但沒有這樣的運氣。 – Shinji 2012-04-23 12:05:43

+0

一邊寫我犯了一個錯字錯誤...檢查更新一: - – Pranav 2012-04-23 12:08:40

+0

再次感謝,但也試過。想想我只是想嘗試在其他地方完成地理編碼。只需在這裏插入lat和long。 – Shinji 2012-04-23 12:41:13

0

繞過速率限制是可能的。請參閱Google Map V3 : Only some markers are displayed,這是完全相同的問題。

這是答案的相關部分:

你需要慢下來的請求。在您提交更多請求時,您可能不得不減慢速度以滿足地理編碼器的要求。我已經在http://acleach.me.uk/gmaps/v3/plotaddresses.htm做了第3版的示例(來自第2版的着名示例) - 您可以看到它開始時請求之間的延遲時間爲100毫秒,但需要在20次迭代後減慢到150毫秒左右。