Я делаю приложение, которое появляется с долготой, широтой, высотой и скоростью.Почему моя информация о CLLocation не отображается?
Всякий раз, когда я запускаю приложение: 1. Данные о местоположении не отображаются в ярлыках | 2. Я получаю это сообщение об ошибке:
fatal error: unexpectedly found nil while unwrapping an Optional value
Что я делаю неправильно? Благодаря!
@IBOutlet weak var longitude: UILabel!
@IBOutlet weak var latitude: UILabel!
@IBOutlet weak var altitude: UILabel!
@IBOutlet weak var speed: UILabel!
var locationManager: CLLocationManager = CLLocationManager()
var startLocation: CLLocation!
@IBAction func reset(sender: AnyObject) {
startLocation = nil
}
func locationManager(manager: CLLocationManager!,
didUpdateLocations locations: [AnyObject]!)
{
var latestLocation: AnyObject = locations[locations.count - 1]
latitude.text = String(format: "%.4f",
latestLocation.coordinate.latitude)
longitude.text = String(format: "%.4f",
latestLocation.coordinate.longitude)
altitude.text = String(format: "%.4f",
latestLocation.altitude)
if startLocation == nil {
startLocation = latestLocation as! CLLocation
}
var distanceBetween: CLLocationDistance =
latestLocation.distanceFromLocation(startLocation)
}
func locationManager(manager: CLLocationManager!,
didFailWithError error: NSError!) {
}
Тогда ...
override func viewDidLoad() {
super.viewDidLoad()
// Location
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
startLocation = nil
// Do any additional setup after loading the view, typically from a nib.
}
tl; dr Какая линия выдает ошибку? –