2016-08-09 3 views
3

マップを他の場所に移動またはズームすることはできません。私はこのチュートリアル:https://www.youtube.com/watch?v=qrdIL44T6FQを使って私の場所を地図に示しました。何らかの理由で、マップを最初にアプリを開いた後、私の場所に非常にゆっくり(+ - 30秒)ズームインします。それから地図の中を移動したいとき、私は傾ける。それは私の現在の場所にとどまります。ここで地図ビューで移動できないswift

は私のコードです:

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) 
 
    } 
 
     
 

 
}

誰もが問題を知っていますか?ありがとう!

答えて

0

Nevermindどこかでミスをしました。このコードは正常に動作している:

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) 
 
    } 
 
    
 
}

関連する問題