0

google.geocoder に複数のアドレスを送信していますが、results[0].geometry.location の値はすべて同じです。コールバックを使用して、呼び出しの非同期性を説明したと思います。アラートを追加して返された値を確認すると、geocoder.geocode( { 'address': addr }... で渡されたアドレスはすべて正しく、返されたステータスは「ok」ですが、緯度/経度は同じです私は JavaScript にあまり精通しておらず、.net 環境も初めてなので、何か助けていただければ幸いです。

このコードは、2012 年 4 月 1 日から 2013 年 12 月頃または 2013 年初頭まで完全に機能していました。Google API で何か変更はありましたか? Google の Web サイトを見ましたが、何も見つかりません。

これが私の最初の呼び出しです:

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

<script type="text/javascript">   

 var geocoder;
 var map;
 var directionsDisplay;
 var directionsRenderer;
 var startPoint;
 var endPoint;

 function initialize() 
 {
  geocoder = new google.maps.Geocoder();

   codeAddress();
   var myOptions = 
   {
    zoom: 12,
    mapTypeId: google.maps.MapTypeId.ROADMAP
   }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);  

   var trafficLayer = new google.maps.TrafficLayer();
   trafficLayer.setMap(map);

   setMarkers(map);

   google.maps.event.addListener(map, 'click', function(event) {
   dirMarker(event.latLng);
   startPoint = event.latLng;
      });
  }


 function codeAddress() 
 {
   var address =  document.getElementById("<%=hCVT.ClientID%>").value;

   geocoder.geocode( { 'address': address}, function(results, status) {

     if (status == google.maps.GeocoderStatus.OK) {
      alert("Status: " + status + "res from CODE ADDRESS -- " +  results[0].geometry.location);  //TO REMOVE
     map.setCenter(results[0].geometry.location);
    } else {
      alert("Geocode of CVT was not successful for the following reason: " + status);
     }
   });
 }

マーカーと情報ウィンドウの情報を設定する機能 (質問に無関係と思われるコードの一部を削除しました)

    function setMarkers(map) 
    {
     // Add markers to the map

      var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'
     };

  var places = new Array([,,,,]);
     var xx = String; 
     xx = document.getElementById("<%=addys.ClientID%>").value;
     var placeholder = xx.split(",");

     var latlng;


     var i = 0;
     for(var y = 0; y < (placeholder.length / 5 - 1); i=i+5)
     {

     places[y, 0] = placeholder[i];
     places[y, 1] = placeholder[i+1]; //Unit Status
     places[y, 2] = placeholder[i+2]; // Long - not used
     places[y, 3] = placeholder[i+3]; // Zindex
     places[y, 4] = placeholder[i+4]; // HTML for information window

     addr = places[y,0];
     ustat = places[y,1];   
     zind = places[y,3];
     iwdata = places[y,4];

     getLatLong(addr, iwdata, ustat, zind, function(latlng, addr, iwdata, ustat, zind)   {






var marker = new google.maps.Marker({
     position: latlng,
     map: map,
     html: iwdata,
     icon: pinImage,
     shadow: pinShadow,
     shape: shape,
     title: addr,
     zIndex: parseInt(places[y,3])
     });

   var infowindow = new google.maps.InfoWindow({
           content: iwdata}); 



  });

   y = y + 1;
  }

   }

問題があると思われる機能は次のとおりです。複数のアドレスが Google に送信されていたので、制限を超えないように組み込みのタイムアウトを追加しました。繰り返しますが、これはすべて約8か月間機能し、突然停止しました. 以前は地図上に複数のマーカーが表示されていましたが、現在は 1 つのマーカーが上書きされているように見えます。これは、緯度/経度の戻り値が codeAddress() 関数の最初の呼び出しと同じであるためです。解決策を見つけるために、戻り値を表示するアラートを追加しています。私は完全に私の頭の上にあった Google JavaScript に私を引き継ぐので、bugzilla の値と混同されていました。

     function getLatLong(addr, iwdata, ustat, zind, callback){

       geocoder.geocode( { 'address': addr}, function(results, status){       
        if (status == google.maps.GeocoderStatus.OK){                       
          callback(results[0].geometry.location, addr, iwdata, ustat, zind);
            } else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {

             window.setTimeout(function() {self.getLatLong(addr, iwdata, ustat, zind, callback);
             },500);
            } else {
            alert("Address Geocode failure: " + addr + " ==== " + status + "Y value: " + zind + " res ---" + res);
            }
    });
    }

誰でもこれで私を助けることができますか?

4

1 に答える 1

0

さて、このコードを何時間も見つめて理解しようとした後、私はついにスマートに配置されたアラートを使用するものに出くわしました。どうやら addr 変数に「'」が含まれていたため、ジオコーダーは緯度/経度データを提供できませんでした。この行を調整しました:

addr = places[y,0].replace(/'/g, "");

すべてが動作するようになりました。

于 2013-03-28T17:42:22.450 に答える