2016-08-09 255 views
3

Ich kann die Karte nicht verschieben oder an andere Orte zoomen. Ich habe dieses Tutorial verwendet: https://www.youtube.com/watch?v=qrdIL44T6FQ, um meinen Standort in der Karte anzuzeigen. Aus irgendeinem Grund zoomt die Karte zuerst sehr langsam (+ - 30 Sekunden) zu meinem Standort, nachdem ich die App geöffnet habe. Dann, wenn ich mich in der Karte bewegen will, kann ich nicht. Es bleibt an meinem aktuellen Standort.In der Kartenansicht kann man sich nicht bewegen swift

Hier ist mein Code:

import UIKit 
 
import MapKit 
 
import CoreLocation 
 

 
class FirstViewController: 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() 
 
     // Dispose of any resources that can be recreated. 
 
    } 
 
    
 
    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.5, longitudeDelta: 0.5)) 
 
     
 
     self.mapView.setRegion(region, animated: true) 
 
     
 
     self.locationManager.startUpdatingLocation() 
 
    
 
    } 
 
    
 
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) { 
 
     print("Errors: " + error.localizedDescription) 
 
    } 
 
     
 

 
}

Hat das Problem jemand wissen? Vielen Dank!

Antwort

0

Niemals habe ich irgendwo einen Fehler gemacht. Dieser Code funktioniert gut:

import UIKit 
 
import MapKit 
 
import CoreLocation 
 

 
class FirstViewController: 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() 
 
     // Dispose of any resources that can be recreated. 
 
    } 
 
    
 
    // MARK: - Location Delegate Methods 
 
    
 
    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: 1, longitudeDelta: 1)) 
 
     
 
     self.mapView.setRegion(region, animated: true) 
 
     
 
     self.locationManager.stopUpdatingLocation() 
 
    } 
 
    
 
    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) 
 
    { 
 
     print("Error: " + error.localizedDescription) 
 
    } 
 
    
 
}