当我缩放 GMaps 自定义标记视图时更改位置

When I zoom GMaps custom markerview changes position

我正在使用 Google 地图,我创建了自定义标记视图并将其设置为我的标记

marker.iconView = CustomMarkerView(frame: CGRect(x: 0, y: 0, width: 198, height: 34))

这是我的自定义标记视图

import UIKit
class CustomMarkerView: UIView {
    var logo = UIImage()
    var adress = UILabel()
    var price = UILabel()
    var icon_like = UIImage(named: "icon_like")
    var icon_direction = UIImage(named: "icon_direction")

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addCustomView()
    }

    init(frame: CGRect, logo: String, adress: String, price: String) {
        super.init(frame: frame)
        self.logo = UIImage(named: logo)!
        self.adress.text = adress
        self.price.text = price
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func addCustomView() {
        self.layer.backgroundColor = UIColor(patternImage: UIImage(named: "bgMarkerView")!).cgColor
    }
}

在我开始缩放地图之前一切正常。如果我缩放它,标记视图将改变位置,但位置坐标不会改变:

我知道这是视图表示的问题,因为实际上 marker.position 没有改变,但是正如您在屏幕上看到的那样,它改变了

我想 google 在这里试图做的是将 "anchor point" 保持在同一坐标。默认情况下,锚点是自定义 UIView.

底部边界的中点

我看到您正在尝试显示 infoView。如果是这种情况,可以使用委托方法:

- (nullable UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker