gpt4 book ai didi

android - 在 Android 上使用 Google map 为数百个标记制作动画

转载 作者:太空狗 更新时间:2023-10-29 15:02:55 25 4
gpt4 key购买 nike

在我的 Android 项目中,我在 Google map 上有超过 300 个标记。从屏幕截图中可以看出,它们是旧金山的车辆。我有车辆的方向和速度,我想在下次调用 API 之前为它们设置 10 秒的动画。

要为一个标记设置动画,我使用以下代码:

static void animateMarkerToICS(Marker marker, LatLng finalPosition, final LatLngInterpolator latLngInterpolator) {
TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() {
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
return latLngInterpolator.interpolate(fraction, startValue, endValue);
}
};
Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");
ObjectAnimator animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);

animator.setInterpolator(new LinearInterpolator());

animator.setDuration(ANIMATION_MILLIS);
animator.start();
}

当我为所有 300 个标记调用此方法时, map 如预期的那样缓慢且响应不灵敏。

问题是,同时激活 300 个标记的最佳方法是什么?是否有一种有效的方法来实现此任务的良好性能?

(我在 Android > 4.0 上使用 Google map v2)

附注如果 map 完全缩小,我不打算运行动画,所以我可能永远不会让所有 300 个标记同时移动,但我仍然希望获得有关解决此问题的最佳方法的反馈。谢谢!

enter image description here

最佳答案

您是否考虑过使用 asynchronous task ?这会将重点从您的主 UI 线程上移开,并将“计算”放到后台。从而使您的 map 更具响应性并且不会滞后。

这是我可能会考虑的事情......

  1. 创建一个异步类。

  2. 在Do后台方法中放入你的marker计算方法等

    protected String doInBackground(Location... params) {
    // Show user a Progress bar/Dialog
    // your markers plotting function here...
    }
  3. 在post post execute function revert back to map

    protected void onPostExecute(String  result) {
    // Revert back to map
    }

请注意,我假设您已经拥有 300 个标记的纬度/经度坐标,并且只绘制它们需要很长时间。但是,如果您没有坐标,您也可以为此创建一个 Asych 任务并释放您的主线程。

关于android - 在 Android 上使用 Google map 为数百个标记制作动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24769141/

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