小概要。由於地理編碼不允許大量的同時請求,我必須在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。我將通過已經擁有的經緯度來改變這種黑客行爲,但現在我希望能夠實現這一目標。
建議非常感謝。
您可以張貼在現場的網站或的jsfiddle或東西的鏈接呢?很難爲您的響應調試代碼片段 – 2012-04-23 17:00:44