0

我已经制作了一个应用程序,可以在谷歌地图中打印多条折线,每条线都以标记 A 开头,最后会有一个标记 B 像JSFIDDLE。问题是当我打印 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 回答