在用户位置中心后释放MKMapView

时间:2015-02-22 23:38:37

标签: ios swift mkmapview

下面的代码效果很好,但是一旦您尝试在地图上滚动或远离用户位置的任何地方,它会向右拉回来并回到用户位置的中心位置。它不会释放它。

在加载后用户位置居中后,你会如何释放它?

import MapKit
import CoreLocation

class MapView : UIViewController, CLLocationManagerDelegate {
    @IBOutlet weak var map: MKMapView!
    var locationManager: CLLocationManager!

    override func viewDidLoad() {
        super.viewDidLoad()
        if (CLLocationManager.locationServicesEnabled()) {
            locationManager = CLLocationManager()
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyBest
            locationManager.requestAlwaysAuthorization()
            locationManager.startUpdatingLocation()
        }
    }
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    let location = locations.last as CLLocation
    let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
    self.map.setRegion(region, animated: true)
}

0 个答案:

没有答案