2016-08-21 79 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之后,它就起作用了!