我有一个坐标数组,我想在Maps API v3中为其创建PolyLines。到目前为止,我已经完成了以下工作。
for (i = 0; i < locations.length; i++) { //locations is an array of Lat, Long
var a = new google.maps.LatLng(locations[i][0], locations[i][1]);
plans.push(a)
bounds.extend(a);
}
var roadPath = new google.maps.Polyline({
path: plans,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
roadPath.setMap(map);
现在的问题是,在创建折线时,最后一点和第一点也被连接起来,如图所示
其中最左边的点是数组
locations
中的第一个点,最右边的是最后一个坐标。如何使红线只贴在道路上,而不像乌鸦飞一样贴在路上? 最佳答案
而不是同时pushing all
个点pass pair
个点,您的问题将得到解决。尝试使用pair of points
绘制路径。如:第一次send origin and first
点,然后second pair is first point and second point
以此类推。
例如:假设您的点数组为:origin,first,seond,third,......,last,destination
。然后将origin,first
发送为first pair
,然后将first,second
发送为second pair
,second and third
发送为third pair
,..,last,destination
作为last pair
到Google路线服务或折线。
如果源和目的地相同,请确保此处不相同,然后不要发送最后一对。