javascript 如何在谷歌地图上动态绘制折线
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19594040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to draw polylines on google maps dynamically
提问by Nirmala Sudhir
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);
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.
我有一个像这样的列表 r=['13.034056,80.250489|13.036324,80.248538|13.026394,80.237562']。我在上面的部分有问题。但我可以静态传递值,并且我得到了预期的折线。提前致谢。
回答by geocodezip
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);