我试图使用CLLocationManager框架来访问用户的位置,但是当我打电话时 self.locationManager.startUpdatingLocation()
locationManager:didUpdateLocations:或locationManager:didFailWithError:都没有被调用。
func currentLatLong() - >无效{
self.currentLatitude = nil
self.currentLongitude = nil
startLocation = nil
self.locationManager = CLLocationManager()
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startMonitoringSignificantLocationChanges()
self.locationManager.startUpdatingLocation()
}
public func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
self.currentLatitude = String(locValue.latitude)
self.currentLongitude = String(locValue.longitude)
self.locationManager.stopUpdatingLocation()
}
public func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print(error)
}
我错过了什么吗?
我也将这些添加到我的.info文件
中NSLocationAlwaysUsageDescription ---我需要位置
NSLocationWhenInUseUsageDescription ---我需要位置