2015-03-02 60 views
0

我有MapView的,其委托的方法需要的MapView不更新位置

func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) { 
    mapView.userTrackingMode = MKUserTrackingMode.None 
    var eye = CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude) 
    var cam = MKMapCamera(lookingAtCenterCoordinate: eye, fromEyeCoordinate: eye, eyeAltitude: 10000) 

    UIView.animateWithDuration(1, animations: {() -> Void in 
     mapView.camera = cam 
    }) 
} 

和它的作品一些随机的方式。它在视图加载时执行,并且当我将地图滚动到另一个国家或城市并缩放时,它可以(有时现在总是)将我返回到当前位置。这很好奇,因为我当前的位置没有改变,代表不应该执行。 我需要做某事这件事情没有发生。所以我想让我的地图只在位置发生变化时才缩放到当前位置,换句话说,我需要有免费的滚动地图。

回答

0

你必须设置你控制器CLLocationManagerDelegate,然后声明一个变量,如:

var locationManager:CLLocationManager = CLLocationManager()

然后在您的viewDidLoad方法:

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.locationManager.delegate = self 
    self.locationManager.stopUpdatingLocation() 

应该防止调用func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!)

请注意,如果您需要使用坐标更新地图中心而无需手动滚动至实际位置,则必须重新组合它。

+0

你不明白我需要和尝试做什么。我想使用委托,所有这一切,但只有当userlocation真正更新时,而不是当我滚动地图时。你的答案是关于另一个案例 – 2015-03-02 15:36:22