添加标记动态的谷歌地图V2为Android [英] Add markers dynamically on Google Maps v2 for Android

查看:132
本文介绍了添加标记动态的谷歌地图V2为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些添加标记动态取决于其示地图的区域的可能性?

what are the possibilities to add markers dynamically depending on the area of the map which is shown?

我有很多标记或let's的说,我的标志需要呈现的很多表现,因为他们都是定制的。我实现了,现在,当一个camerachange被解雇只有40标记绘制。所以在这个时候,我总是呈现40个新的标志物时cameraposition改变。

I have a lot of markers or let´s say my markers need a lot of performance to be rendered, cause they are custom. I implemented it now, that only 40 markers are drawn when a "camerachange" was fired. So at this time i always render 40 new markers when cameraposition was changed.

我也读到了可运行和处理程序,是他们更多的选择?是否有人知道这些可能性是最好的,让UI线程isn't受阻?

I read about runnable and handler, are their more options? Does someone know which of these possibilities is the best, so that ui-thread isn´t blocked?

推荐答案

我会建议使用集群库可用于谷歌地图Android的API V2之一。

I would suggest using one of clustering libraries available for Google Maps Android API v2.

Android地图扩展程序除了集群可以为你做了很多工作。该API非常相似,谷歌官方库。
如果你不希望使用集群的一切,你仍然可以实现你的目标有:

Android Maps Extensions apart from clustering can do a lot of work for you. The API is very similar to official Google library.
If you don't want to use clustering at all, you can still achieve your goal with:

map.setClustering(new ClusteringSettings()
    .enabled(false)
    .addMarkersDynamically(true)); // I didn't change the API to match your title ;)

Clusterkraf 主要集中在动画集群。

Clusterkraf mainly focuses on animated clustering.

Android地图utils的的截至发稿未集群合并到主分支,但你可以看到集群分支

Android Maps Utils as of this writing doesn't have clustering merged into the main branch, but you can see clustering branch.

如果你想$ C C它自己$,我可以建议这些方法:

If you want to code it yourself, I can suggest these approaches:

  • 加入标记只S在 VisibleRegion (同​​样的事情Android地图扩展使用上述code时一样) ,例如,从这里我演示项目:<一href="https://github.com/mg6maciej/android-maps-v2-demo/blob/master/NewMapsDemo/src/pl/mg6/newmaps/demo/AddOnlyVisibleMarkersExampleActivity.java">AddOnlyVisibleMarkersExampleActivity.java
  • 加入标记 S使用处理程序,例如这里:<一href="https://github.com/mg6maciej/android-maps-v2-demo/blob/master/NewMapsDemo/src/pl/mg6/newmaps/demo/AddMarkersInBackgroundExampleActivity.java">AddMarkersInBackgroundExampleActivity.java
  • 在上面的搭配;这可以帮助很多与应用程序的响应时,有潜在的数百标志在屏幕上(你应该避免使用群集)
  • adding Markers only in VisibleRegion (same thing Android Maps Extensions does when using code above), example from my demo project here: AddOnlyVisibleMarkersExampleActivity.java
  • adding Markers using Handler, example here: AddMarkersInBackgroundExampleActivity.java
  • mix of the above; this can help a lot with app responsiveness when there are potentially hundreds of markers on screen (which you should avoid by using clustering)

这篇关于添加标记动态的谷歌地图V2为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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