Dictionary swift iOS 9中的当前位置
我在plist中添加了nslocationwhenUsageDescription并将其设置为YES,下面是我的代码:Dictionary swift iOS 9中的当前位置,dictionary,location,Dictionary,Location,我在plist中添加了nslocationwhenUsageDescription并将其设置为YES,下面是我的代码: func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let location = locations.last let center = CLLocationCoordinate2D(latitude: locati
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(region, animated: true)
print(location)
print(center)
}
但它仍然不起作用。它只是没有显示任何东西。
似乎从未调用过locationManager函数。它甚至不打印任何日志 刚刚通过添加以下内容解决了此问题:
locationManager = CLLocationManager()
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
并将locationManager声明为类变量<代码>var locationManager:CLLocationManager代码>