【发布时间】:2019-01-15 08:26:45
【问题描述】:
我将GoogleMaps 用于我的应用程序,并且我使用requestWhenInUseAuthorization 正确设置了Info.plist、locationManager...didChangeAuthorization 中的所有内容,但我仍然遇到错误
EXC_BAD_INSTRUCTION
即使我设置正确。下面是我的代码。
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
let camera = GMSCameraPosition.camera(withTarget: (self.locationManager.location?.coordinate)!, zoom: zoomLevel)
self.mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
self.view = self.mapView
self.initializeTheLocationManager()
self.mapView.isMyLocationEnabled = true
这是我的 locationManager 委托
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedAlways || status == .authorizedWhenInUse {
mapView.delegate = self
manager.startUpdatingLocation()
} else {
manager.requestWhenInUseAuthorization()
}
}
注意:我好像申请了两次requestWhenInUseAuthorization。
【问题讨论】:
-
到底是在哪里崩溃的?
-
你会遇到什么问题?
-
@mag_zbc this
self.locationManager.location?.coordinate)!它返回nil尽管我已经允许模拟器请求位置。 -
在模拟器中,您无法获取当前位置。您应该为此使用真实设备
-
@AlvinQuezon 您是否已将自定义位置添加到您的模拟器?
标签: ios swift google-maps cllocationmanager google-maps-sdk-ios