我正在尝试使用谷歌地图整合核心位置,但程序不断崩溃,调试人员无法深入了解我做错了什么。我在从一个视图转换到另一个视图时配置地图,但在转换之前崩溃了。我使用自定义转换(演示控制器)。我不认为这是问题所在,但为了以防万一,我想提一下。
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.requestAlwaysAuthorization()
locationManager.distanceFilter = 50
locationManager.delegate = self
let defaultLocation = CLLocation(latitude: -33.869405, longitude: 151.199)
print(popUpView2.bounds) //(0.0, 0.0, 290.0, 410.0)
let camera = GMSCameraPosition.camera(withLatitude: defaultLocation.coordinate.latitude, longitude: defaultLocation.coordinate.longitude, zoom: zoomLevel)
mapView = GMSMapView.map(withFrame: popUpView2.bounds, camera: camera) // **Program Crashes Here**
mapView.settings.myLocationButton = true
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.isMyLocationEnabled = true
popUpView2.addSubview(mapView)
mapView.mapType = GMSMapViewType.terrain
mapView.isHidden = true
locationManager.startUpdatingLocation()
答案 0 :(得分:0)
我必须创建一个容器视图,只需更改:
popUpView2.addSubview(mapView)
为:
mapContainerView.addSubview(mapView)
我在Interface Builder中这样做并设置了适当的约束。