【发布时间】:2016-12-15 16:47:00
【问题描述】:
我无法将地图移动或缩放到其他位置。我使用本教程:https://www.youtube.com/watch?v=qrdIL44T6FQ 在地图中显示我的位置。出于某种原因,地图在打开应用程序后首先会非常缓慢(+- 30 秒)放大到我的位置。然后,当我想在地图中移动时,我不能。它停留在我当前的位置。
这是我的代码:
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)
}
}
有人知道这个问题吗?谢谢!
【问题讨论】:
标签: swift dictionary view location