2016-08-21 57 views
0

我已經設置了實現GMSMapViewDelegate,將它設置爲self,並且我仍然無法讓任何代理函數工作。以下是我的代碼示例:iOS上沒有調用GMSMapViewDelegate函數

class UserViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate { 

    var mapView: GMSMapView! 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 

     if mapView == nil { 
      mapView = GMSMapView() 
     } 

     mapView.delegate = self 

    } 

    func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) { 
     print(position) 
    } 

    func mapView(mapView: GMSMapView, willMove gesture: Bool) { 
     print(gesture) 
    } 

    func mapView(mapView: GMSMapView, idleAtCameraPosition position: GMSCameraPosition) { 
     print(position) 
    } 

的MapView功能打印任何東西都沒有。我已經檢查了代表並知道它已正確設置。我錯過了什麼嗎?

+0

我對使用Google地圖的其他方面(例如設置地點和標記)沒有任何問題。這只是代表職能,我一直在遇到問題。 –

+1

給你的代碼,你想實現這些,編輯你的文章:)不能真的幫助否則閱讀: - http://stackoverflow.com/help/how-to-ask – Dravidian

+0

你是否從你的地圖視圖連接到當前類 –

回答

0

因此,我認爲,經過
if mapView == nil { mapView = GMSMapView() }
設置委託將是正確的,但事實並非如此。我在
mapView = GMSMapView.mapWithFrame(CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height), camera: camera) 中設置了實際的邊界,並且之後我放置了mapView.delegate = self之後,它就起作用了!