GMSMarker iOS问题

Pau*_* T. 2 google-maps google-maps-api-3 ios gmsmapview

我使用此代码在Google Map for iOS上创建标记.

self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    self.mapView.myLocationEnabled = YES;
    self.mapView.accessibilityElementsHidden = NO;
    self.mapView.frame = self.view.bounds;
    self.mapView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.mapView.delegate = self;
    self.mapView.settings.myLocationButton = YES;
    [self.view addSubview:self.mapView];

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.map = self.mapView;
Run Code Online (Sandbox Code Playgroud)

但我需要标记看起来像这样:

在此输入图像描述

我知道如何使用Apple Map,但我需要使用Google Map(因为在某些城市Apple Map几乎没有显示任何内容).

对于谷歌地图,我发现只有这样的代码:

marker.icon = image; // image from xib file
Run Code Online (Sandbox Code Playgroud)

所以我需要为xib为每个标记创建图像.我会有很多标记,所以可能采用这种方法我会得到记忆警告.

有人知道更好的方法来实现这样的标记吗?

Joe*_*ind 9

由于GMSMarker只允许将UIImage设置为图标,因此我实现了类似这样的东西:(它在Swift中,但对于Objective C,概念是相同的)

var gasView = UIView(frame:CGRectMake(0, 0, 30, 37))
//Add Label
var lblPrecio = UILabel(frame: CGRectMake(0, 37-18, 30, 10))
lblPrecio.text = "hello"
lblPrecio.textAlignment = NSTextAlignment.Center
gasView.addSubview(lblPrecio)
//Add Logo
var logo = UIImageView(frame: CGRectMake(30-23, 2, 16, 16))
logo.image = UIImage(named: "Logo")
gasView.addSubview(logo)
//Add Callout Background Image
gasView.backgroundColor = UIColor(patternImage: UIImage(named: "Callout")!)

marker.icon = imageFromView(gasView)
Run Code Online (Sandbox Code Playgroud)

函数imageFromView的位置如下:

private func imageFromView(aView:UIView) -> UIImage {
    if(UIScreen.mainScreen().respondsToSelector("scale")) {
        UIGraphicsBeginImageContextWithOptions(aView.frame.size, false, UIScreen.mainScreen().scale)
    }
    else {
        UIGraphicsBeginImageContext(aView.frame.size)
    }
    aView.layer.renderInContext(UIGraphicsGetCurrentContext())
    var image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.