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

问题描述:

我使用以下代码marker clustering(用于产生与水桶集群图标)使用Google map sdk如何在Google地图上显示聚集标记的确切数量?

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

它被适当地标记聚类但它是表示在地图上的10+50+号码。例如,如果标记物的数量35则当标记物的数量超过50则显示50+等显示在地图上,10+(参照以下附图)。我想在地图上显示集群上的exact number of markers!我的意思是,如果标记的数量36然后我想36,而不是10+。如果有人可以帮助!

截图:

enter image description here

参考:marker-clustering!!

我们可以通过改变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]; 
} 

我做了什么时,我只是改变其他部分,并设置textexact number而不是string with +

+0

真棒解决方案!我想知道它是否会损害表演? –

+0

不,我还没有打上任何性能问题!!!! – Lion