将地名标签添加到 iOS 中的 Google 地图标记

Adding Place Name Label to Google Map Markers in iOS

我在 Google 地图上显示了标记,我想添加每个地方名称的 UILabel。

看到 GMSMarker 属性 标题是特定于标记的 infoWindow 并且从可用研究的少量选择中,可能需要制作自定义图标?

是否有任何 iOS(更容易)实施的例子?

为了创建自定义标记,您必须继承 GMSMarker 并根据您的需要创建它 iconView

来自Google Maps documentation

  • (UIView*) iconView [read, write, assign]

Marker view to render. If left nil, falls back to the icon property instead.

示例:

class CustomMarker: GMSMarker {

    var label: UILabel!

    init(labelText: String) {
        super.init()

        let iconView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 50, height:     80)))
        iconView.backgroundColor = .white

        label = UILabel(frame: CGRect(origin: .zero, size: CGSize(width:     iconView.bounds.width, height: 40)))
        label.text = labelText
        iconView.addSubview(label)

        self.iconView = iconView
    }
}

用法:

let marker = CustomMarker(labelText: "my_label")
marker.position = CLLocationCoordinate2D(latitude: 0, longitude: 0)
marker.map = //your mapView object

请注意,iconView 仅用于为要呈现的标记创建降价。您的标记不会像往常一样难以处理 UIView,因此向其添加任何手势或复杂的可滚动视图都不会产生任何效果。