我试图从此位置绘制一条线到地图中显示的另一个位置。我已经检索出坐标并为每个位置放置一个标记但是我如何画一条连接它们的线?虽然我有代码,但我认为我错误地使用了它。任何帮助,将不胜感激。感谢。
//create the markers
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng<?php echo $location['locationOne']; ?>,
map: map,
title: "First location"
});
var marker2 = new google.maps.Marker({
position: new google.maps.LatLng<?php echo $location['locationTwo']; ?>,
map: map,
title: "Second location"
});
var marker3 = new google.maps.Marker({
position: new google.maps.LatLng<?php echo $location['locationThree']; ?>,
map: map,
title: "Third location"
});
var marker4 = new google.maps.Marker({
position: new google.maps.LatLng<?php echo $location['locationFour']; ?>,
map: map,
title: "Fourth location"
});
var marker5 = new google.maps.Marker({
position: new google.maps.LatLng<?php echo $location['locationFive']; ?>,
map: map,
title: "Fifth location"
});
这是我对如何添加的代码感到困惑。尝试了几次,但它不起作用:
var line = new google.maps.Polyline({
map: map,
path: [<?php echo $location['locationOne']; ?>, <?php echo $location['locationTwo']; ?>, <?php echo $location['locationThree']; ?>, <?php echo $location['locationFour']; ?>, <?php echo $location['locationFive']; ?>],
strokeWeight: 7,
strokeOpacity: 0.8,
strokeColor: "#000000"
});
答案 0 :(得分:0)
您将坐标对而不是LatLngs
传递给路径选项。您需要为每个坐标对创建一个新的LatLng
对象(即new google.maps.LatLng(...)
)。如下:
path: new google.maps.LatLng([<?php echo $location['locationOne']; ?>), new google.maps.LatLng(<?php echo $location['locationTwo']; ?>), ...,
顺便说一句,您是否使用括号输出$ location ['locationXXX']变量?我认为你是。