ios谷歌地图自定义标记

时间:2014-09-03 09:54:10

标签: ios google-maps-markers

您好我正在使用谷歌地图,我想使用像下面的图像标记 marker i want

我已完成代码

UIView *markerview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 55, 102)];
markerview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"glow-marker2.png"]];
UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 47, 70)];
imgview.backgroundColor = [UIColor whiteColor];
imgview.contentMode = UIViewContentModeScaleAspectFit;
imgview.image = img;
imgview.layer.cornerRadius = 7;
imgview.layer.masksToBounds = YES;
[markerview addSubview:imgview];
marker.icon = [self imageWithView:markerview];
marker.map = mapview;

它给我输出

getting output

谁能告诉我为什么这个黑色背景会来?怎么解决?

2 个答案:

答案 0 :(得分:0)

我认为问题在于你将UIView设为图像。尝试以下代码

    - (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}

答案 1 :(得分:0)

我认为您的问题是将图片设置为您视图的背景。

markerview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"glow-marker2.png"]];

我建议将背景视为一种清晰的颜色并设置opaque=NO并将图像设置为imageview,并将此图像添加为markerview子视图

希望你能解决问题。