如何在 google 地图上显示聚类标记的确切数量?

How to show the exact number of clustered markers on google map?

我使用下面的代码 marker clustering(用于生成带桶的集群图标)使用 Google map sdk

   id<GMUClusterIconGenerator> iconGenerator = [[GMUDefaultClusterIconGenerator alloc]initWithBuckets:@[@10,@50,@100,@500] backgroundImages:@[cluster1,cluster2,cluster3,cluster4]];

它正确地聚类标记,但它在地图上显示 10+50+ 数字。例如,如果标记数为 35,则在地图上显示 10+,当标记数超过 50 时,则显示 50+ 等(请参阅下面的附加屏幕截图)。我想在地图上的群集图像上显示 exact number of markers!!我的意思是如果标记的数量是 36 那么我想要 36 而不是 10+。如果有人可以帮助!

截图:

参考:marker-clustering!!

我们可以通过改变GMUDefaultClusterIconGeneratorclass的一种方法来管理它。

GMUDefaultClusterIconGenerator.m中替换下面的方法,

 - (UIImage *)iconForSize:(NSUInteger)size {
    NSUInteger bucketIndex = [self bucketIndexForSize:size];
    NSString *text;

    // If size is smaller to first bucket size, use the size as is otherwise round it down to the
    // nearest bucket to limit the number of cluster icons we need to generate.
    if (size < _buckets[0].unsignedLongValue) {
    text = [NSString stringWithFormat:@"%ld", (unsigned long)size];
    } else {
    text = [NSString stringWithFormat:@"%ld+", _buckets[bucketIndex].unsignedLongValue];
  }
   if (_backgroundImages != nil) {
    UIImage *image = _backgroundImages[bucketIndex];
    return [self iconForText:text withBaseImage:image];
}
     return [self iconForText:text withBucketIndex:bucketIndex];
 }

 - (UIImage *)iconForSize:(NSUInteger)size {
    NSUInteger bucketIndex = [self bucketIndexForSize:size];
    NSString *text;

    // If size is smaller to first bucket size, use the size as is otherwise round it down to the
   // nearest bucket to limit the number of cluster icons we need to generate.
   if (size < _buckets[0].unsignedLongValue) {
     text = [NSString stringWithFormat:@"%ld", (unsigned long)size];
   }


  else{
    text = [NSString stringWithFormat:@"%ld", (unsigned long)size];
  }

  if (_backgroundImages != nil) {
    UIImage *image = _backgroundImages[bucketIndex];
    return [self iconForText:text withBaseImage:image];
  }
  return [self iconForText:text withBucketIndex:bucketIndex];
 }

我所做的是,我刚刚更改了其他部分并将 text 设置为 exact number 而不是 string with +!