Lio*_*ion 3 objective-c ios google-maps-sdk-ios google-maps-ios-utils
我正在使用以下代码,用于marker clustering(使用存储桶生成群集图标)Google map sdk,
id<GMUClusterIconGenerator> iconGenerator = [[GMUDefaultClusterIconGenerator alloc]initWithBuckets:@[@10,@50,@100,@500] backgroundImages:@[cluster1,cluster2,cluster3,cluster4]];
Run Code Online (Sandbox Code Playgroud)
它正确地将标记聚类,但是在地图上显示10+或50+数字。例如,如果标记数量在地图35上显示10+,则标记数量超过50则在地图上显示50+等(请参阅下面的屏幕截图)。我想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];
}
Run Code Online (Sandbox Code Playgroud)
与
- (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];
}
Run Code Online (Sandbox Code Playgroud)
我所做的是,我只更改了else部分并设置text为exact number而不是string with +!