在swift中单击时删除标记

时间:2016-06-12 07:35:02

标签: swift google-maps marker

我试图在点击上添加标记,我做到了! 但我想在谷歌地图中只有2个标记。 我该怎么办 ?! 这是我在swift中的代码

    mapView.delegate = self

    }

func mapView(mapView: GMSMapView, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {

    let marker = GMSMarker(position: coordinate)
    marker.appearAnimation = kGMSMarkerAnimationPop
    marker.title = ""
    marker.snippet = ""
    marker.map = mapView   
}

我想要一个家的标记和一个目标标记

1 个答案:

答案 0 :(得分:0)

使用此功能解决:

var counterMarker: Int = 0 


func mapView(mapView: GMSMapView, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {

        if counterMarker < 2
        {
            counterMarker += 1
            let marker = GMSMarker(position: coordinate)
            marker.appearAnimation = kGMSMarkerAnimationPop

            marker.map = mapView


        }
    }