2016-10-03 21 views
0

我知道可以在標記的infowindow中捕捉點擊。 I followed the documentation here收聽Swift中的InfowWindow點擊

全部都寫在Objective C所以我試圖將其轉換爲Swift,這裏是我的代碼:

func mapView(_ mapView: GMSMapView, didTap InfoWindowOfMarker: GMSMarker) { 
     print("You tapped infowindow") 

    } 

但是,這是沒有得到根本解僱。該方法有什麼問題?

+0

我的遲到道歉更新,現在請看看它是完美的工作俺們.. – vaibhav

+0

你缺少設置委託,我看到有一個'_'在你的方法內標記可能導致不執行檢查我的答案。 – vaibhav

回答

5

您需要使用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 
    } 
+0

你好。你的代碼是一個自定義的infowindow。我不是在尋找那個。抱歉。我正在尋找信息標記 –

+0

的點擊事件,那麼你可以在這裏使用標記變量,如果你不需要自定義窗口.. – vaibhav

+0

我需要點擊infowindow,而不僅僅是標記 –