以下是获取用户定位的 Delegate
extension MapViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first{
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let span = MKCoordinateSpan(latitudeDelta: 0.075, longitudeDelta: 0.075)
let region = MKCoordinateRegion(center: center, span: span)
self.mapView.setRegion(mapView.regionThatFits(region), animated: false)
locationManager.stopUpdatingLocation()
}
}
}
MKCoordinateSpan 的 latitudeDelta 和 longitudeDelta 数值越小地图的放大系数应该越高,但是有个问题就是用户定位(小蓝点)无法居中,并且放大系数越大,偏移量越大,如下图所示,请问一下大家有什么好的办法解决这个问题?