2

我使用以下代碼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!!

回答

3

我們可以通過改變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

相關問題