GoogleMaps Swift Tap Marker

时间:2016-07-27 19:42:20

标签: ios swift google-maps google-maps-api-3 google-maps-markers

我在这里有这个功能,无论何时轻敲标记,它都会设法执行操作。但我只想对某些标记起作用,比如数组中包含的标记

markers_array = [GMSMarkers]()

有没有办法让mapView函数只对这些特定的标记执行?

func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {
            if let marker = marker as? ChosenMarker {
        if marker.touchEnabled == true {
            // Have to show which one is selected too.
            print("Hello")
            let setAsHomeButton: SetAsHomeButtonView = SetAsHomeButtonView(marker: marker)
            self.view.addSubview(setAsHomeButton)
            self.setupSetAsHomeButton(setAsHomeButton)
        } else {

        }
    }
    return true
}

谢谢

1 个答案:

答案 0 :(得分:2)

You can create a GMSMarkers subclass with a boolean like touchEnabled and in mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) you cast the parameter "marker" to your custom class. Finally you can check if the touchEnabled is enable.