Google maps 谷歌地图代表

Google maps 谷歌地图代表,google-maps,google-maps-markers,google-maps-sdk-ios,swift5,Google Maps,Google Maps Markers,Google Maps Sdk Ios,Swift5,我在我的项目中使用谷歌地图。当点击infoWindowOfMarker调用委托方法时,我想给用户两个选项:mapView(uuMapView:GMSMapView,didTapInfoWindowOfMarker marker:GMSMarker) 如果我只想执行一个操作,我可以检索标记中的信息并执行我的操作。实际上,我想给用户2个选项:查看详细信息(将用户发送到新的视图控制器)和访问(根据标记的位置属性和用户的当前位置从google API获取方向) 这两个选项将是两个按钮 我不知道如何在点击

我在我的项目中使用谷歌地图。当点击infoWindowOfMarker调用委托方法时,我想给用户两个选项:
mapView(uuMapView:GMSMapView,didTapInfoWindowOfMarker marker:GMSMarker)

如果我只想执行一个操作,我可以检索标记中的信息并执行我的操作。实际上,我想给用户2个选项:查看详细信息(将用户发送到新的视图控制器)和访问(根据标记的位置属性和用户的当前位置从google API获取方向) 这两个选项将是两个按钮

我不知道如何在点击按钮时将marker参数传递给调用的方法

请查看代码,并让我知道任何其他方法,我可以做到这一点

class ItemMarker: GMSMarker {
    let item: Item
    init(item: Item){
        self.item = item
        super.init(position: item.coordinate)
        //and necessary initialization
    }}

class MapViewController: GMSMapViewDelegate{
    @IBOutlet weak var actionStackView: UIStackView!
    @IBoutlet weak var mapView: GMSMapView!
    var currentUser: User!
    var users = [User]()
    var items = [Item]()
    override viewDidLoad(){
        super.viewDidLoad()
        //implement code for mapView
        self.currentUser = UserManager.shared.currentUser
        self.users = UserManager.shared.users
        users.forEach {self.items.append(contentOf: $0.items}
        self.items.forEach {let marker = ItemMarker(item: $0)
            marker.map = mapView}
    }

    @objc func seeDetailButtonTapped(_ sender: UIButton){
        //here I want to verify if the user is the owner of the item he wants to see the detail,
        //then allow him to modify it and present the new view controller modally.
        //if the user is not the owner, then not allowing editing, and show the new view controller.
        //i guess for that I need to be able to have the marker for that.
    }

    @objc func visitButtonTapped(_ sender: UIButton) {
        //here I want to use the user current location,
        //the item location, get the directions for the user,
        //I need the ItemMarker to do that.
    }

    func mapView(_ mapView: GMSMapView, didtapInfoWindowOfMarker marker: GMSMarker)
    {
        let visitButton = UIButton(type: .roundedRect)
        visitButton.setTitle(Utilities.visit, for: .normal)
        visitButton.backgroundColor = UIColor.systemBlue
        visitButton.addTarget(self, action: #selector(visitButtonTapped(_:)), for: .touchUpInside)
        let seeDetail = UIButton(type: .roundedRect)
        seeDetail.setTitle(Utilities.detail, for: .normal)
        seeDetail.backgroundColor = UIColor.systemGray
        seeDetail.addTarget(self, action: #selector(showDetailHouse(_:)), for: .touchUpInside)
        actionStackView.addArrangedSubview(visitButton)
        actionStackView.addArrangedSubview(seeDetail)
        let stackViewHeight = actionStackView.intrinsicContentSize.height
        let topInset = self.mapView.safeAreaInsets.top
        mapView.padding = UIEdgeInsets(top: topInset, left: 0.0, bottom: stackViewHeight, right: 0.0)
        UIView.animate(withDuration: 0.25) {
            actionStackView.bottomAnchor.constraint(equalTo: self.mapView.safeAreaLayoutGuide.bottomAnchor, constant: 2.0).isActive = true
            actionStackView.alpha = 0.9 }
    }
}

如何将标记传递给seedTail方法和visitButtonTapped方法 从UIButton创建一个具有所需属性的子类,然后可以在
tap
handler中使用它

class UIButtonWithMarker: UIButton {
    var itemMarker: ItemMarker?
}

func mapView(_ mapView: GMSMapView, didtapInfoWindowOfMarker marker: GMSMarker)
{
    let visitButton = UIButtonWithMarker(type: .roundedRect)
    visitButton.itemMarker = marker as? ItemMarker
    visitButton.setTitle(Utilities.visit, for: .normal)
    visitButton.backgroundColor = UIColor.systemBlue
    visitButton.addTarget(self, action: #selector(visitButtonTapped(_:)), for: .touchUpInside)

    let seeDetail = UIButtonWithMarker(type: .roundedRect)
    seeDetail.itemMarker = marker as? ItemMarker
    seeDetail.setTitle(Utilities.detail, for: .normal)
    seeDetail.backgroundColor = UIColor.systemGray
    seeDetail.addTarget(self, action: #selector(showDetailHouse(_:)), for: .touchUpInside)
}

@objc func seeDetailButtonTapped(_ sender: UIButtonWithMarker){
    if itemMarker = sender.itemMarker {
        //use itemMarker here
    }
}

@objc func visitButtonTapped(_ sender: UIButtonWithMarker) {
    if itemMarker = sender.itemMarker {
        //use itemMarker here
    }
}
谢谢