javascript - 动画谷歌地图折线

标签 javascript google-maps polyline animated

我想在谷歌地图中绘制一条动画(测地线)折线,有点像这样:http://planefinder.net/route/SFO/

我找到了许多关于如何沿多段线为符号设置动画的教程,但没有关于如何为多段线本身从源到目的地设置动画的教程。

有什么提示吗?我应该从哪里开始?

非常感谢任何帮助。

最佳答案

我在以下方面取得了一些成功:

 var departure = new google.maps.LatLng(dept_lat, dept_lng); //Set to whatever lat/lng you need for your departure location
 var arrival = new google.maps.LatLng(arr_lat, arr_lng); //Set to whatever lat/lng you need for your arrival location
 var line = new google.maps.Polyline({
      path: [departure, departure],
      strokeColor: "#FF0000",
      strokeOpacity: 1,
      strokeWeight: 1,
      geodesic: true, //set to false if you want straight line instead of arc
      map: map,
 });
 var step = 0;
 var numSteps = 250; //Change this to set animation resolution
 var timePerStep = 5; //Change this to alter animation speed
 var interval = setInterval(function() {
     step += 1;
     if (step > numSteps) {
         clearInterval(interval);
     } else {
         var are_we_there_yet = google.maps.geometry.spherical.interpolate(departure,arrival,step/numSteps);
         line.setPath([departure, are_we_there_yet]);
     }
 }, timePerStep);

这基本上是使用一个间隔来重绘路径。在每一步,可见的动画路径在从出发到到达直到最终到达位置的总路径中所占的比例更大。

关于javascript - 动画谷歌地图折线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16800865/

相关文章:

javascript - google.maps.LatLng 返回一个返回 'a' 的函数。为什么?

c# - Adobe Illustrator 中的多段线简化是如何工作的?

javascript - 如何在jquery中重复一个句子

javascript - 如何确保异步函数在继续之前返回值

javascript - JQuery 和 Ajax 调用新创建的元素

android - 如何为信息 View 适配器调用项目点击监听器?

javascript - 用复选框填充 div

android - AutocompleteFragment 结果返回一个具有 null 属性的地方

java - 折线颜色不变

IOS 无法添加多边形标记 仅绘制折线 未添加标记