2015-02-09 2 views
1

Не знаете, почему это не работает? любая помощь будет принята с благодарностью. Thnks.Почему я получаю Неустранимая ошибка: неожиданно найден нуль при распаковке необязательного значения ... вот мой код:

import UIKit 
import MapKit 
import CoreLocation 

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { 

    var locationManager:CLLocationManager! 
    @IBOutlet weak var mapView: MKMapView! 

    @IBAction func nowButton(sender: AnyObject) { 
    } 

    @IBOutlet weak var mapLabel: UILabel! 

    @IBAction func bookButton(sender: AnyObject) {  
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     locationManager = CLLocationManager() 
     locationManager.requestAlwaysAuthorization()   
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 
     locationManager.delegate = self 
     locationManager.startUpdatingLocation() 

     mapView.showsUserLocation = true 
     mapView.delegate = self 

     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { 
     let regionToZoom = MKCoordinateRegionMake(manager.location.coordinate, MKCoordinateSpanMake(0.05, 0.05)) 
     mapView.setRegion(regionToZoom, animated: true) 
    } 

} 
+1

Какая строка дает вам ошибку? –

+0

В дополнение к вышесказанному, все ваши '' IBOutlet 'ы связаны? – Rich

ответ

0

Возможная ошибка причина заключается в из-за этой линии в методе didUpdateLocations делегата:

let regionToZoom = MKCoordinateRegionMake(manager.location.coordinate, MKCoordinateSpanMake(0.05, 0.05)) 

Вам нужно создать область, как показано ниже линии (заменить эту строку выше строки):

let regionToZoom = MKCoordinateRegion(center: manager.location.coordinate, span: MKCoordinateSpanMake(0.05, 0.05))); 
Смежные вопросы

 Смежные вопросы