如何动态地在谷歌地图上绘制多段线 [英] how to draw polylines on google maps dynamically

查看:236
本文介绍了如何动态地在谷歌地图上绘制多段线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Google地图上绘制多段线。动态获取价值。

I cant able to draw polylines on google maps. am getting the value dynamically.

var flightPlanCoordinates=[];
n = "new google.maps.LatLng(";
q = ")";
var flightPlanCoordinates = new Array();
for(i=0;i<len;i++)
{  

  o =n+r[i].split(',')[0]+","+r[i].split(',')[1]+q;

  flightPlanCoordinates.push(o);   

}   


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

flightPath.setMap(map);
google.maps.event.addDomListener(window, 'load', initialize);

我有这样的列表r = ['13.034056,80.250489 | 13.036324,80.248538 | 13.026394,80.237562 ]。
我上面的部分有问题。但我可以静态传递值,我得到了预期的折线。预先感谢。

i have an list like this r=['13.034056,80.250489|13.036324,80.248538|13.026394,80.237562']. i have an problem the above part. but i can able to pass value statically and i got the polyline as i expected.Thanks in advance.

推荐答案

这适用于我。

This works for me.

var r=['13.034056,80.250489|13.036324,80.248538|13.026394,80.237562'];
var coordinates = r[0].split("|");
var flightPlanCoordinates = new Array();
for(i=0;i<coordinates.length;i++)
{  
  var point =new google.maps.LatLng(coordinates[i].split(',')[0],coordinates[i].split(',')[1]);
  flightPlanCoordinates.push(point);   
}   


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

flightPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);

工作示例

这篇关于如何动态地在谷歌地图上绘制多段线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆