如何使用单个标记多次点击

时间:2019-05-09 02:23:38

标签: ios swift dictionary sdk marker

通过点击,它使标记为无穷大。我想要一个标记,我点击了。再三,一而再再而三。没有很多标记。

enter image description here

我使用了MapView.clean()。但会删除所有标记。

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
{
        let marker = GMSMarker(position: coordinate)
        marker.position.latitude = coordinate.latitude
        marker.position.longitude = coordinate.longitude
        print("hello")
        print(markerr.position.latitude)
        let ULlocation = markerr.position.latitude
        let ULlgocation = markerr.position.longitude
        print(ULlocation)
        print(ULlgocation)
        marker.map = self.mapView
}

1 个答案:

答案 0 :(得分:0)

didTapAt coordinate方法之外创建标记,并在此方法中更改其坐标

class ViewController: UIViewController, GMSMapViewDelegate {

    let marker = GMSMarker()

    override func viewDidLoad() {
        super.viewDidLoad()
        marker.map = self.mapView
    }
    func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
    {
        marker.position = coordinate
    }
}

enter image description here