小さなまとめ。ジオコーディングでは多くの同時リクエストが許可されず、Google マップに 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
何が起こっているのか誰にも分かりますか?
ps。緯度と経度を既に取得しているため、将来このハックを変更しますが、今のところこれを機能させたいと考えています。
提案は大歓迎です。