在Android中,如何根据包含的标记数量更改聚类图像?

How to change cluster image according to the number of marker it included, in Android?

下图根据其大小包含不同的簇样式。这正是我在 Android 中尝试做的事情。我正在使用 android-maps-util 中的 ClusterManager

这是服务器人员使用的 javascript 代码。 如果可能的话,我需要同样的想法来这样做。

gmap.mc.styles_ = [{ url: markersBaseLocation + 'm1.png', height: 53, width: 53 }, { url: markersBaseLocation + 'm2.png', height: 56, width: 57 }, { url: markersBaseLocation + 'm3.png', height: 66, width: 66 }, { url: markersBaseLocation + 'm4.png', height: 78, width: 78 }, { url: markersBaseLocation + 'm5.png', height: 90, width: 90 }];

您可以通过提供自己的自定义渲染器来做到这一点。

mClusterManager.setRenderer(new DefaultClusterRenderer<MyItem>(mContext, googleMap, mClusterManager) {
        @Override
        protected void onBeforeClusterRendered(Cluster<MyItem> cluster, MarkerOptions markerOptions) {
            // use cluster.getSize() to get the number of markers inside the cluster.
        }

可在 https://github.com/googlemaps/android-maps-utils.git 中找到此演示代码。看看里面 "CustomMarkerClusteringDemoActivity.java"