Javascript 在地图上画一条带有实线和虚线的路径

Javascript 在地图上画一条带有实线和虚线的路径,javascript,google-maps-api-3,Javascript,Google Maps Api 3,根据maps API v3上的文档,有两个单独的虚线和实线示例。。我有一个长的和长的数组,我想标记路径,交替标记实线和虚线。。 代码如下 var lat_lng = new Array(); var latlngbounds = new google.maps.LatLngBounds(); for (var i = 0; i < markers.length; i++) { var data = markers[i]; var my

根据maps API v3上的文档,有两个单独的虚线和实线示例。。我有一个长的和长的数组,我想标记路径,交替标记实线和虚线。。 代码如下

    var lat_lng = new Array();
    var latlngbounds = new google.maps.LatLngBounds();
    for (var i = 0; i < markers.length; i++) {
        var data = markers[i];
        var myLatlng = new google.maps.LatLng(data.lat, data.lng);
        lat_lng.push(myLatlng);
      var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: data.title
        });
      //  console.log(i%2);

        var lineSymbol = {
              path: 'M 0,-1 0,1',
              strokeOpacity: 1,
              scale: 4
            };



        latlngbounds.extend(marker.position);
        (function (marker, data) {
            google.maps.event.addListener(marker, "click", function (e) {
                infoWindow.setContent("Location:"+data.location_name+"<br> Battery Status :"+data.battery_status+"<br> Form :"+data.tablename+"<br> Status :"+data.status+"<br> Time :"+new Date(data.time)+"<br> Weather :"+data.weather);
                infoWindow.open(map, marker);
            });
        })(marker, data);
    }
    map.setCenter(latlngbounds.getCenter());
    map.fitBounds(latlngbounds);
    //***********ROUTING****************//
    //Initialize the Path Array
    var path = new google.maps.MVCArray();
    //Initialize the Direction Service
    var service = new google.maps.DirectionsService();

    //Set the Path Stroke Color
    if(i%2==0)
  {
        var poly = new google.maps.Polyline({ map: map, strokeColor: '#4986E7',strokeOpacity: 0,
              icons: [{
                icon: lineSymbol,
                offset: '0',
                repeat: '20px'
              }], });   
  }
else
  {
    var poly = new google.maps.Polyline({ map: map, strokeColor: '#4986E7'});

  }
var lat_lng=new Array();
var latlngbounds=new google.maps.latlngbounds();
对于(var i=0;i电池状态:“+data.Battery\u Status+”
形式:“+data.tablename+”
状态:“+data.Status+”
时间:“+new Date(data.Time)+”
天气:“+data.Weather”; 信息窗口。打开(地图、标记); }); })(标记、数据); } map.setCenter(latlngbounds.getCenter()); 地图边界(latlngbounds); //***********路由****************// //初始化路径数组 var path=new google.maps.MVCArray(); //初始化方向服务 var service=new google.maps.DirectionsService(); //设置路径笔划颜色 如果(i%2==0) { var poly=new google.maps.Polyline({map:map,strokeColor:'#4986E7',strokeOpacity:0, 图标:[{ 图标:lineSymbol, 偏移量:“0”, 重复:“20px” }], }); } 其他的 { var poly=new google.maps.Polyline({map:map,strokeColor:'#4986E7'}); }
我在一个箱子的末尾画了一条线,但一次只能画一个实线或虚线。

一个单件只能有一种样式(实线与虚线)。需要将每个需要不同样式的线段作为单独的多段线

代码片段:

var地理编码器;
var映射;
变量标记=[{
拉脱维亚:42,
液化天然气:-72,
标题:“0”
}, {
拉脱维亚:43,
液化天然气:-73,
标题:“1”
}, {
拉脱维亚:43,
液化天然气:-74,
标题:“2”
}, {
拉脱维亚:42,
液化天然气:-75,
标题:“3”
}, {
拉丁美洲:41,
液化天然气:-76,
标题:“4”
}];
函数初始化(){
var map=new google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var lat_lng=[];
var latlngbounds=new google.maps.latlngbounds();
对于(var i=0;i电池状态:“+data.Battery\u Status+”
形式:“+data.tablename+”
状态:“+data.Status+”
时间:“+new Date(data.Time)+”
天气:“+data.Weather”; 信息窗口。打开(地图、标记); }); })(标记、数据); //***********路由****************// 如果(横向长度>1){ //设置路径笔划颜色 如果(i%2==0){ var poly=new google.maps.Polyline({ 地图:地图, strokeColor:“#4986E7”, 笔划不透明度:0, 图标:[{ 图标:lineSymbol, 偏移量:“0”, 重复:“20px” }], 路径:拉图液化天然气 }); }否则{ var poly=new google.maps.Polyline({ 地图:地图, strokeColor:“#4986E7”, 路径:拉图液化天然气 }); } 拉图液化天然气=[]; 横向推进(myLatlng); } } map.setCenter(latlngbounds.getCenter()); 地图边界(latlngbounds); } google.maps.event.addDomListener(窗口“加载”,初始化)
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}

单曲只能有一种风格(实心与虚线)。需要将每个需要不同样式的线段作为单独的多段线

代码片段:

var地理编码器;
var映射;
变量标记=[{
拉脱维亚:42,
液化天然气:-72,
标题:“0”
}, {
拉脱维亚:43,
液化天然气:-73,
标题:“1”
}, {
拉脱维亚:43,
液化天然气:-74,
标题:“2”
}, {
拉脱维亚:42,
液化天然气:-75,
标题:“3”
}, {
拉丁美洲:41,
液化天然气:-76,
标题:“4”
}];
函数初始化(){
var map=new google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var lat_lng=[];
var latlngbounds=new google.maps.latlngbounds();
对于(var i=0;i电池状态:+data.bat