dsb12300
2017-04-08 08:16
浏览 32
已采纳

使用折线连接多个标记

I tried this code but no luck with polylines,may be because of small issue, i couldn't get polylines that connect the markers.
I need to connect multiple marker with polylines any alternative code also is welcome.

var locations = [];
// call php array
var latitude = <?php echo json_encode($latitude); ?>;
var longitude = <?php echo json_encode($longitude); ?>;
for(var i=0;i<20;i++){
 locations.push(["current",latitude[i], longitude[i]]);
}

var marker;
          function initMap() {
           var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 5,
          center: new google.maps.LatLng(12.289774217827633, 76.30976921188685)
          });

var flightPath = new google.maps.Polyline({
                                            path: locations,
                                            geodesic: true,
                                            strokeColor: '#000000',
                                            strokeOpacity: 1.0,
                                            strokeWeight: 3
  });


flightPath.setMap(map);
 var infowindow = new google.maps.InfoWindow();
 var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
}

图片转代码服务由CSDN问答提供 功能建议

我试过这段代码,但折线运气不好,可能是因为小问题,我无法得到折线 连接标记。
我需要用折线连接多个标记任何替代代码也是受欢迎的。

  var locations = []; 
 //调用php数组 
var latitude =&lt;?php echo json_encode($ latitude);  ?&gt ;; 
var longitude =&lt;?php echo json_encode($ longitude);  ?&gt ;; 
for(var i = 0; i&lt; 20; i ++){
 locations.push([“current”,latitude [i],longitude [i]]); 
} 
 
var标记 ; 
函数initMap(){
 var map = new google.maps.Map(document.getElementById('map'),{
 zoom:5,
 center:new google.maps.LatLng(12.289774217827633,76.30976921188685)  )
 
))
 
 
 
 
 
 \团体路径=新google.maps.Polyline({
路径:位置,
 \ geodesic:true,
 strokeColor:'#000000',
 strokeOpacity:1.0,
 strokeWeight  :3 
}); 
 
 
flightPath.setMap(map); 
 var infowindow = new google.maps.InfoWindow(); 
 var marker,i; 
 
 for(i = 0;  i&lt; locations.length; i ++){
 marker = new google.maps.Marker({
 position:new google.maps.LatLng(locations [i] [1],locations [i] [2]),  
 map:map 
}); \  n 
 google.maps.event.addListener(marker,'click',(function(marker,i){
 return function(){
 infowindow.setContent(locations [i] [0]); 
 infowindow  .open(map,marker); 
} 
})(marker,i)); 
} 
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题