如何沿路线制作自定义 Google 地图标记的动画?
我使用 JavaScript 和 Google Maps API 为手持设备编写了一个小型应用程序,现在我需要使用计时器功能将我的标记图标沿着路线移动到地图上的任何位置。 我有一个男人图标,我需要在地图上自动移动它。 我怎样才能做到这一点?
I have written a small application for a handheld device using JavaScript and Google Maps API's, now II need to move my marker icon anywhere on the map along a route using a timer function. I have a man icon and I need to move it automatically on the map. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有一个非常酷的示例:
http://www.kmcgraphics.com/google/
A pretty cool example is here:
http://www.kmcgraphics.com/google/
不幸的是,官方 GMaps 集合中没有自动标记移动功能。
然而,如果你有一个GRoute,那就意味着你有一组点。 要循环遍历路线步骤,您可以使用类似以下的内容:
当然,您可能希望使用计时器异步执行此操作:
为了更平滑的移动,您可以从已有的点中插入点。
Unfortunately, there is no automatic-marker-movement function in the official GMaps collection.
However, if you have a GRoute, that would mean you have a set of points. To loop through the route steps, you could use something like this:
Of course, you'll probably want to do this asynchronously using the timers:
For even smoother movement, you could interpolate the points from those you already have.
这是我的解决方案,适用于 v3 API。 这不是以固定速度,而是基于计算的路线持续时间来对标记进行动画处理。 这里有一个速度因素,例如,您可以比实际情况快 10 倍地行驶通过该路线。
我尝试尽可能简单地做到这一点。 随意使用它。
用法:
Here is my solution that works with the v3 API. This animates the marker not with a fixed velocity, but based on the calculated route duration. There is a speed factor, so for example you can drive through the route 10x faster than in reality.
I've tried to do it as simple as possible. Feel free to use it.
Usage: