如何在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+
。如果有人可以帮助!
截图:
答
我们可以通过改变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 +
!
真棒解决方案!我想知道它是否会损害表演? –
不,我还没有打上任何性能问题!!!! – Lion