如何在谷歌地图上显示聚集标记的确切数量?

时间:2016-12-19 08:25:35

标签: ios objective-c google-maps-sdk-ios google-maps-ios-utils

我使用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+。如果有人可以帮忙!

屏幕截图:

enter image description here

参考:marker-clustering!!

1 个答案:

答案 0 :(得分:4)

我们可以通过更改GMUDefaultClusterIconGenerator类的一种方法来管理它。

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 +