Reputation: 27438
I am using below code for marker clustering
(for generating cluster icon with buckets) using Google map sdk
,
id<GMUClusterIconGenerator> iconGenerator = [[GMUDefaultClusterIconGenerator alloc]initWithBuckets:@[@10,@50,@100,@500] backgroundImages:@[cluster1,cluster2,cluster3,cluster4]];
It is clustering markers properly but It is showing 10+
or 50+
numbers on map. For example, If number of markers are 35
then it is displaying 10+
on map, when number of markers exceeds 50 then it is displaying 50+
etc.(refer attached screenshot below). I want to display exact number of markers
on cluster Image on map!! I mean if number of markers are 36
then i want 36
instead of 10+
. If any one can help!
Screenshot :
Reference : marker-clustering!!
Upvotes: 4
Views: 2874
Reputation: 27438
We can manage it by changing one method of GMUDefaultClusterIconGenerator
class.
In GMUDefaultClusterIconGenerator.m
replace below method,
- (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];
}
with
- (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];
}
What i have done is, I have just change else portion and set text
as exact number
instead of string with +
!
Upvotes: 7