gpt4 book ai didi

javascript - 在运行时使折线更长

转载 作者:行者123 更新时间:2023-12-02 18:14:33 25 4
gpt4 key购买 nike

我有一个谷歌地图应用程序,我可以在多段线上移动标记。我正在生成一个新的目的地点(latlng 坐标)。我想将折线延伸到这个新的目的地点。

有人可以告诉我如何将折线的终点移动到 map 上的另一点。

我在这里使用了polyline[index].getPath(),我可以看到构成路线的所有经纬度坐标对。如何添加到这条路线以使其更长或更短?

最佳答案

简单。如果您只想向现有点数组添加一个附加点,则可以这样做:

var currentPath = polyline[index].getPath();
var newPoint = new google.maps.LatLng(40.781321,-73.965855);
currentPath.push(newPoint);
polyline[index].setPath(currentPath);

如果您想更改当前最后一个点的位置,请尝试以下操作:

var currentPath = polyline[index].getPath();
var newPoint = new google.maps.LatLng(40.781321,-73.965855);
currentPath.setAt(currentPath.getLength()-1, newPoint);
polyline[index].setPath(currentPath);

关于javascript - 在运行时使折线更长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19417935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com