Şu anda kullanıcıların uygulamada konum bilgilerini almamı gerektiren bir proje üzerinde çalışıyorum. Başlangıçta ben sadece çalışan bir harita görünümünü göstermek için kodlanmış, ancak o zaman on line hata EXC_BAD_INSTRUCTION almaya devam location.I kullanıcıları göstermekSwift Xcode'da şu anki yerini bulma Bulunduğunuz yer buluyorum
self.mapView.showsUserLocation yapmak istedim = true
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Location Delegate Methods
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2DMake(location!.coordinate.latitude, location!.coordinate.latitude)
let region = MKCoordinateRegion(center: center, span:MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.startUpdatingLocation()
}
Büyük olasılıkla: self.mapView sıfırdır, çünkü Interface Builder'da Harita Görünümü'ne bağlı değildir – Gereon