我使用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+
。如果有人可以帮忙!
屏幕截图:
答案 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 +
!