0

Google マップに複数のポリラインを出力するアプリケーションを作成しました。各行はマーカー A で始まり、最後にJSFIDDLEのようなマーカー B があります。問題は、10〜15行のマーカーを印刷するときに、特にマーカーBが欠落していることです.

誰でもこれの解決策を教えてください

私のJSFIDDLEを見てください

私のコードは以下のとおりです

$(function(){

 var map    = new google.maps.Map(document.getElementById("map"), {
                  center: new google.maps.LatLng(11.275387916698238, 75.8015380957031),
                  zoom: 12
               }),



     routes = [
         {"origin":"mavoor road, kozhikode","destination":"p t usha road, kozhikode","status":"START"},
         {"origin":"vellimadukunnu, kozhikode","destination":"p t usha road, kozhikode","status":"START"}
         ,{"origin":"p t usha road, kozhikode","destination":"mavoor road, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"mankavu, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"ghandhi road, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"ghandhi road, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode, Kerala, India","destination":"francis road, kozhikode, Kerala, India","status":"START"},
         {"origin":"p t usha road, kozhikode, Kerala, India","destination":"francis road, kozhikode, Kerala, India","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"cooperative hospital, eranjipalam, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"beach, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"azchavattam, kozhikode","status":"START"},
         {"origin":"p t usha road, kozhikode","destination":"aradhana tourist home, kallai road, kozhikode","status":"START"},
         {"origin":"IIM, Kozhikode","destination":"VELLIMADUKUNNU, KOZHIKODE","status":"START"},
         {"origin":"MANKAVU, KOZHIKODE","destination":"P T USHA ROAD, KOZHIKODE","status":"START"},
         {"origin":"P T Usha road, kozhikode, Kerala, India","destination":"Mavoor road, kozhikode, Kerala, India","status":"START"},
         {"origin":"P T Usha Road, Kozhikode","destination":"Mankavu, Kozhikode","status":"START"},
         {"origin":"P T USHA ROAD, KOZHIKODE","destination":"GANDHI ROAD, KOZHIKODE","status":"START"},
         {"origin":"P t usha road, kozhikide, kerala India","destination":"Francis road, kozhikide, kerala India","status":"START"},
         {"origin":"P T Usha Road, Kozhikode, Kerala, India","destination":"Francis Road, Kozhikode, Kerala, India","status":"START"},
         {"origin":"P T Usha Road, Kozhikode, Kerala, India","destination":"Francis Road, Kozhikode, Kerala, India","status":"START"}],

     rendererOptions = {
                preserveViewport: true,
                map:map,
                polylineOptions:{strokeColor:'#FF3300',
                                 strokeWeight: 5},        
                suppressMarkers:true,
                routeIndex:0
              },
     directionsService = new google.maps.DirectionsService();
    var i=0;
var infowindow = new google.maps.InfoWindow();
      $.each(routes,
        function(i,obj){//<--anonymous function

        var request = {
                origin: obj.origin,
                destination: obj.destination,
                travelMode: google.maps.TravelMode.DRIVING
              },

            directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
            directionsService.route(request, function(result, status) {

              if (status == google.maps.DirectionsStatus.OK) {

var lat = result.routes[0].legs[0].start_location.lat();
var lon = result.routes[0].legs[0].start_location.lng();

    var lat1 = result.routes[0].legs[0].end_location.lat();
var lon1 = result.routes[0].legs[0].end_location.lng();             



                  try{  

                  var marker1 = new google.maps.Marker({
    position: new google.maps.LatLng(lat, lon),
                      icon:'https://mts.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=B&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1',
        map: map
      });

                            google.maps.event.addListener(marker1, 'click', (function(marker1, i) {
        return function() {
          infowindow.setContent('hh');
          infowindow.open(map, marker1);
        }
      })(marker1, i));                      

                  }catch(e){alert(e)}






                       try{  

                  var marker2 = new google.maps.Marker({
    position: new google.maps.LatLng(lat1, lon1),
                      icon:'https://mts.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png&text=A&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1',
        map: map
      });



                            google.maps.event.addListener(marker2, 'click', (function(marker2, i) {
        return function() {
          infowindow.setContent('hdddh');
          infowindow.open(map, marker2);
        }
      })(marker2, i));                                     

                  }catch(e){alert(e)}




                  directionsDisplay.setDirections(result);
              }
            });  
      i++;
        });});
4

1 に答える 1

0

不足しているマーカーは他のマーカーの下にあります (このフィドルでドラッグできるようにしました。また、クォータ/レート制限に達していることに注意してください (OVER_QUERY_LIMIT のステータス応答を取得しています)。

var marker1 = new google.maps.Marker({
  position: new google.maps.LatLng(lat, lon),
  draggable: true,
  icon:'https://mts.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=B&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1',
  map: map
});

var marker2 = new google.maps.Marker({
  position: new google.maps.LatLng(lat1, lon1),
  draggable: true,
  icon:'https://mts.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png&text=A&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48&scale=1',
  map: map
});

これは便利な変更です (エラーがいつ発生したかを確認できます)。

  directionsDisplay.setDirections(result);
} else { 
  // output error status messages
  document.getElementById('info').innerHTML += "Directions Request["+i+"] Failed: "+status + "<br>"; 
}
于 2013-10-10T02:30:50.250 に答える