您需要使用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
}
我的遲到道歉更新,現在請看看它是完美的工作俺們.. – vaibhav
你缺少設置委託,我看到有一個'_'在你的方法內標記可能導致不執行檢查我的答案。 – vaibhav