简体   繁体   English

Google Maps Clustering无法使用动态数据

[英]Google Maps Clustering not working with dynamic data

I have a problem with the clustering of GoogleMaps . 我对GoogleMaps的群集有问题。 In my app im updating the map when the User zooms in or scrolls over the Map. 在我的应用程序中,当用户放大或滚动地图时,我会更新地图。 Im using the OnCameraIdleListener ( link ) for this: OnCameraIdleListener使用OnCameraIdleListenerlink ):

@Override
public void onCameraIdle() {
   clearItems();
   do API Call
}

When this happens im doing an API call with the new radius and im receiving a new list of objects that are visible inside my current radius. 发生这种情况时,我会使用新的半径进行API调用,并且会收到新的对象列表,这些列表在我当前的半径内可见。 After i've received the data im drawing the new POIs to my map. 在我收到数据后,将新的兴趣点绘制到地图上。 Therefore i iterate over a list and for each element i create a cluster item and add it to the Cluster Manager. 因此,我遍历一个列表,并为每个元素创建一个集群项目并将其添加到集群管理器中。

CustomClusterItem clusterItem = new CustomClusterItem(new LatLng(item.getLocation().getLatitude(), item.getLocation().getLongitude()), poi); 
mClusterManager.addItem(clusterItem);

and after the iteration im calling 并在迭代后即时通话

mClusterManager.cluster();

Sadly the clustering does not work. 遗憾的是,群集无法正常工作。 It doesn't matter how far im zooming out of the map for example. 例如,即时缩放距离地图有多远都没关系。 Is there something im missing? 我缺少什么吗?

Thanks in advance! 提前致谢!

I just had 4 POIs on my Map and the Clustering just starts with 5 items. 我的地图上只有4个POI,而聚类仅以5个项目开始。 So there is no mistake. 因此没有错误。 I just didn't know that there is a size configured by default. 我只是不知道默认情况下是否配置了大小。 If someone wants to achieve clustering with less then 5 items you can use 如果某人想要实现少于5个项目的集群,则可以使用

@Override
protected boolean shouldRenderAsCluster(Cluster<T> cluster) {
    //start clustering if at least 2 items overlap
    return cluster.getSize() > 1;
}

this method from the DefaultClusterRenderer ( https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java ). DefaultClusterRenderer( https://github.com/googlemaps/android-maps-utils/blob/master/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java )中的此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM