我最近更新到最新的 google maps sdk for ios (1.4) 并且我有一个自定义标记,我将其用作集群标记并显示该标记内的标记数量。
- (UIImage *)icon {
UIImage *img = [UIImage imageNamed:DEFAULT_ICON];
NSString *text = [NSString stringWithFormat:@"%d",[self.markersInCluster count]];
UIFont *font = [UIFont boldSystemFontOfSize:14];
CGSize textSize = [text sizeWithFont:font];
CGPoint point = CGPointMake((img.size.width - textSize.width) /2, (img.size.height - textSize.height) /2);
UIGraphicsBeginImageContext(img.size);
[img drawInRect:CGRectMake(0,0,img.size.width,img.size.height)];
CGRect rect = CGRectMake(point.x, point.y, img.size.width, img.size.height);
[[UIColor whiteColor] set];
[text drawInRect:CGRectIntegral(rect) withFont:font];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
这在升级之前一直正常工作,现在似乎只有在 GMSMarker init 上更改此图标属性时才会呈现图像,否则会显示默认标记。