【发布时间】:2016-06-06 06:20:46
【问题描述】:
我在view controller 上有一个mapKit。我希望map 向用户显示当前位置。它似乎有效,但用户位置卡在屏幕的右侧。当您尝试将其从右侧滚动时,它会弹回到那里。无法理解我做错了什么?任何帮助将不胜感激。
override func viewDidLoad() {
super.viewDidLoad()
clientAddressTextField.text = clientAddress
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
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.stopUpdatingLocation()
}
亲切的问候
韦恩
【问题讨论】:
-
您是否设置了地图视图约束?听起来像是在屏幕外的一半
-
谢谢,我不敢相信我忘记了这样的事情。问题解决了。