2017-04-08 90 views
0

我有我的谷歌地圖出現在我的iOS應用程序,並在地圖上用下面的代碼在我的視圖控制器被吸引我的多邊形成功:GMSPolygon爲什麼不響應水龍頭?

let camera = GMSCameraPosition.camera(withLatitude: 37.886080, longitude: -122.137585, zoom: 7.0) 
mapView = GMSMapView.map(withFrame: CGRect(x: screenWidth*0.03, y: 245, width: screenWidth*0.94, height: screenHeight*0.45), camera: camera) 
self.view.addSubview(mapView) 

let rect = GMSMutablePath() 
rect.add(CLLocationCoordinate2D(latitude: 37.886080, longitude: -122.137585)) 
rect.add(CLLocationCoordinate2D(latitude: 37.899356, longitude: -122.130203)) 
rect.add(CLLocationCoordinate2D(latitude: 37.900101, longitude: -122.104282)) 
rect.add(CLLocationCoordinate2D(latitude: 37.879644, longitude: -122.101192)) 
let polygon = GMSPolygon(path: rect) 
polygon.fillColor = UIColor.flatWatermelonDark.withAlphaComponent(0.5) 
polygon.strokeColor = .black 
polygon.strokeWidth = 2 
polygon.isTappable = true 
polygon.map = mapView 

我也是貫徹GMSMapViewDelegate在我的視圖控制器,並具有下面的函數作爲我的視圖控制器的一部分:

func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) { 
    print("Jesus loves you") 
    print("User Tapped Layer: \(overlay)") 

} 

這是我的理解是,因爲我的多邊形變量的.isTappable值設置爲true,當多邊形tappend委託方法應被調用,並打印「耶穌愛你「和被挖掘的疊加層。當我點擊多邊形時沒有發生這種打印,這意味着didTap委託方法沒有被調用。我在設置中丟失了什麼?

回答

2

我是一個總的白癡。

是不是在viewDidLoad中地圖視圖的委託屬性設置爲自我。

mapView.delegate = self 

現在問題解決了!