GMSMapViewDelegate未被调用

时间:2016-09-19 16:43:58

标签: ios swift swift3 google-maps-sdk-ios

我不知道,但是当我在xcode 7中运行我的应用程序并在ios 9.1的iphone上运行时,didTapAtCoordinate仍然有效。但现在迁移到xcode 8并将代码升级到Swift 3并在ios 10的iphone上运行后,似乎没有调用以下内容:

 func mapView(mapView: GMSMapView, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
        print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
    }
    func mapView(mapView: GMSMapView, idleAtCameraPosition cameraPosition: GMSCameraPosition) {
        print("camera changed")
    }

我添加了这个class ViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate。确保在mapView.delegate = self初始化后调用mapView。以下代码位于loadView,我甚至在mapView.delegate = self中添加了viewDidLoad

let camera = GMSCameraPosition.camera(withLatitude: 35.98917593, longitude: -95.94740106, zoom: 6.0)
            mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
            mapView.isMyLocationEnabled = true
            mapView.mapType = kGMSTypeSatellite
            mapView.delegate = self
            view = mapView

如何解决此问题?

1 个答案:

答案 0 :(得分:7)

您只需要在viewDidLoad

初始化委托
mapView.delegate = self