OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在谷歌地图上显示聚集标记的确切数量? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:28
标题: ios - 如何在谷歌地图上显示聚集标记的确切数量?

我正在使用以下代码进行 marker clustering(用于生成带有桶的集群图标),使用 Google map sdk

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

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

截图:

enter image description here

引用:marker-clustering!!



Best Answer-推荐答案


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

GMUDefaultClusterIconGenerator.m 替换下面的方法,

 - (UIImage *)iconForSizeNSUInteger)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 *)iconForSizeNSUInteger)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];
 }

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

关于ios - 如何在谷歌地图上显示聚集标记的确切数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41218459/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4