GMSMapViewDelegate未被调用

Jay*_*ayo 2 ios google-maps-sdk-ios swift swift3

我不知道,但是当我在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")
    }
Run Code Online (Sandbox Code Playgroud)

我加了这个class ViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate.并确保在初始化mapView.delegate = self之后调用mapView它.下面的代码是在loadView,我甚至增加mapView.delegate = selfviewDidLoad:

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
Run Code Online (Sandbox Code Playgroud)

我如何解决这个问题?

小智 7

你只需要初始化委托 viewDidLoad

mapView.delegate = self
Run Code Online (Sandbox Code Playgroud)