-1

小さなまとめ。ジオコーディングでは多くの同時リクエストが許可されず、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。緯度と経度を既に取得しているため、将来このハックを変更しますが、今のところこれを機能させたいと考えています。

提案は大歓迎です。

4

2 に答える 2

0

コールバック関数に引数を渡す必要があるが、setInterval()での追加パラメーターの送信をサポートしていないInternet Explorerで機能する必要がある場合は、匿名関数を使用してコールバックを呼び出します。

var time =setInterval(function(){ codeAddress(location, name, contract, vestigingID); },1000);
于 2012-04-23T12:02:56.230 に答える
0

レート制限を回避することは可能です。Google マップ V3を参照してください: 一部のマーカーのみが表示されますが、これはまったく同じ問題です。

これはその答えの関連部分です:

リクエストを遅くする必要があります。より多くのリクエストを送信すると、おそらく、ジオコーダーを満たすためにリクエストをさらに遅くする必要があります。http://acleach.me.uk/gmaps/v3/plotaddresses.htmでバージョン 3 の例を作成しました (バージョン 2 の例から)。20回の繰り返しの後、約150ミリ秒まで遅くなります。

于 2012-04-24T15:24:23.457 に答える