我不知道,但是当我在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
如何解决此问题?
答案 0 :(得分:7)
您只需要在viewDidLoad
mapView.delegate = self