Android开未聚集的标志 [英] Android Get the markers that are not clustered

查看:235
本文介绍了Android开未聚集的标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,我使用谷歌地图Android版API工具图书馆

I'm developing an android application and I'm using Google Maps Android API Utility Library.

要成为我使用该库的集群部分更具体。现在我的问题:

To be more specific I'm using the cluster part of that library. Now to my question:

我感兴趣的是显示在地图上,但当前未加入群集的标记。我已经尝试了不同的东西,但不能换我的头周围。那种认为工作的事情是所有渲染标志的物品保存在一个数组列表然后比较标记的位置在屏幕上的地图经纬度范围,如果标记是在屏幕范围则标记信息将在不同的ArrayList中添加内后来在ListView显示。这样做的问题是,当我缩小,标记仍然是 renderedPersonItems 数​​组中,并将于即使这些标记现在聚集列表视图显示出来。我不能明确的 renderedPersonItems 阵列引起标记只在一个生命周期呈现一次。所以我在寻找不同的解决方案。这是我走到这一步:

I'm interested in the markers that are shown on the map but that are currently not clustered. I've tried different stuff but can't wrap my head around it. The thing that kind of works is to save all the rendered marker items in a arraylist then compare the marker positions to LatLng bounds of the map on screen, if the markers are inside the screen bounds then the markers info will be added in a different arraylist to later be shown in a listview. The problem with that is when I zoom out, the markers are still in the renderedPersonItems array and will show up in the listview even if those markers are now clustered. I can not clear renderedPersonItems array cause the markers only render once in a lifecycle. So I'm looking for a different solution. This is what I got so far:

code在DefaultClusterRenderer:

Code in DefaultClusterRenderer:

@Override
protected void onBeforeClusterItemRendered(PersonItem personItem, MarkerOptions markerOptions){
    markerOptions.title(personItem.personName);

    if(!renderedPersonItems.contains(personItem)){
        renderedPersonItems.add(personItem);
    }
}

code的主要活动:

Code in main activity:

LatLngBounds personOnScreenBounds = googleMap.getProjection().getVisibleRegion().latLngBounds;

for(PersonItem person : clusterPersonRenderer.getRenderedPersonItems()){
   if(PersonsOnScreenBounds.contains(person.getPosition())){
     personMarksOnScreen.add(getPersonObjectWithId(person.personId));
   }
}

在此先感谢!

推荐答案

我可以推荐你一个凉爽的Andr​​oid的地图图书馆。 Android地图扩展 https://github.com/mg6maciej/android-maps-extensions

I can recommend you another cool android-map library. Android Maps Extensions https://github.com/mg6maciej/android-maps-extensions

我用它在我的应用程序,它看起来很好。这可能是不容易重新实现它在你的应用程序,但你可以尝试。

I use it in my app and it looks fine. It could be not easy to reimplement it in your app, but you could try.

要解决你的问题,你可以做这样的事情:

To solve your problem you can make something like this:

List<Marker> markers = mMap.getDisplayedMarkers();
for (Marker marker : markers) {
    if(!marker.isCluster()) {
        //
    }
}

这篇关于Android开未聚集的标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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