在位置发生变化时保留地图缩放级别

时间:2017-08-08 05:28:22

标签: ios swift3 mapkit

我正在使用MKMapView应用程序。但是当放大到当前用户位置的地图时,地图会变焦。但是当当前位置发生变化时,地图会自动缩小到原始位置。即使位置发生变化,如何保持相同的缩放级别。谢谢。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location = locations.last
    let latestlocation:CLLocation = locations[locations.count-1]
    let a = latestlocation.coordinate.latitude
    let b = latestlocation.coordinate.longitude
    let center = CLLocationCoordinate2D(latitude: a, longitude: b)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpanMake(0.05, 0.05))
    self.mapView.setRegion(region, animated: false)
    mapView.setUserTrackingMode(.follow, animated: true)
    self.mapView.showsUserLocation = true
}

0 个答案:

没有答案