Google Maps v2 上的动画标记 [英] Animating markers on Google Maps v2

查看:30
本文介绍了Google Maps v2 上的动画标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 v2 API 在 Google 地图上制作标记动画的最佳方法是什么?

What is the best way to animate markers on Google Maps using v2 API?

我正在开发一个以地图为中心的游戏,我可以跟踪人们的位置并将他们显示在地图上供彼此查看.当人们移动时,我想将一个标记从他当前的位置动画到他的最新位置.每个人都有一个方向,所以我需要适当地旋转标记.

I am working on a map-centered game where I track locations of people and display them on the map for each other to see. As people move, I want to animate a marker from his current to his latest position. Every person has a direction, so I need to rotate the marker appropriately.

使用新的 Google Maps API 的最佳方法是什么?

What is the best way to do it using the new Google Maps API?

推荐答案

一些 Google 工程师提供了一个很好的演示视频,其中包含一些优雅的示例代码,关于如何为所有不同版本的安卓:

Some Google engineers have provided a nice demo video with some elegant sample code about how to animate markers from a starting point to an ending point, for all various versions of Android:

相关代码在这里:

https://gist.github.com/broady/6314689

还有一个很好的演示视频,所有这些都在行动.

And a nice demo video of all of it in action.

http://youtu.be/WKfZsCKSXVQ

以下已弃用的旧答案

在文档中,提到不能更改标记图标:

In the documentation, it is mentioned that Marker Icons cannot be changed:

图标

为标记显示的位图.如果图标未设置,则显示默认图标.您可以使用 defaultMarker(float) 指定默认图标的替代颜色.一旦创建了标记,就无法更改图标.

A bitmap that's displayed for the marker. If the icon is left unset, a default icon is displayed. You can specify an alternative coloring of the default icon using defaultMarker(float). You can't change the icon once you've created the marker.

Google Maps API v2 文档

您将不得不跟踪特定标记,可能使用类似于此处描述的方法:将标记链接到对象,然后确定您需要更新哪个标记.在标记上调用 .remove(),然后根据方向"创建一个旋转的图像;您需要,使用该图像创建一个新标记,然后将新标记添加到地图中.

You're going to have to keep track of specific markers, perhaps using a method similar to that described here: Link a Marker to an Object, then figure out which marker you need to update. Call .remove() on the marker, then create a rotated image depending on the "direction" you want, create a new Marker with that image, and add the new Marker to the map.

您不需要清除"地图,只需删除您要修改的标记,创建一个新标记,然后将其添加回地图.

You do not need to "clear" the map, simply remove the marker you want to modify, create a new one, then add it back to the map.

遗憾的是,新的 Maps API 还不是很灵活.希望 Google 继续改进它.

Unfortunately, the new Maps API is not very flexible yet. Hopefully Google continues to improve upon it.

这篇关于Google Maps v2 上的动画标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆