收听Swift中的InfowWindow点击
我知道可以在标记的infowindow中捕捉点击。 I followed the documentation here。收听Swift中的InfowWindow点击
全部都写在Objective C
所以我试图将其转换为Swift
,这里是我的代码:
func mapView(_ mapView: GMSMapView, didTap InfoWindowOfMarker: GMSMarker) {
print("You tapped infowindow")
}
但是,这是没有得到根本解雇。该方法有什么问题?
您需要使用GMSMapView
的代表以及一些以前的设置参见下文。
声明使用的GMSMapViewDelegate
方法和设置委托给self
:
class yourClassName: UIViewController,GMSMapViewDelegate
mapView?.delegate = self
方法来检测信息窗口抽头:
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
print("infowindow tapped")
}
方法来检测GMSMarker
抽头:
func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {
print("tapped on marker")
if marker.title == "myMarker"{
print("handle specific marker")
}
return true
}
方法来创建自定义的信息窗口:
func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
let infoWindow = Bundle.main.loadNibNamed("nibName", owner: self, options: nil).first as! ClassName
infoWindow.name.text = "title"
infoWindow.address.text = "relevant address"
infoWindow.photo.image = UIImage(named: "imageName")
return infoWindow
}
你好。你的代码是一个自定义的infowindow。我不是在寻找那个。抱歉。我正在寻找信息标记 –
的点击事件,那么你可以在这里使用标记变量,如果你不需要自定义窗口.. – vaibhav
我需要点击infowindow,而不仅仅是标记 –
我的迟到道歉更新,现在请看看它是完美的工作俺们.. – vaibhav
你缺少设置委托,我看到有一个'_'在你的方法内标记可能导致不执行检查我的答案。 – vaibhav