2012-03-09 80 views
2

我使用下面的代码,当用户按下一个按钮地图视图始终中心的地图

[mapview setShowsUserLocation:YES]; 

,然后follwoing将地图向TE用户的位置,让我的位置

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation  
{ 
    [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES]; 
} 

我的问题是如何防止地图始终集中在我的位置?我想让用户平移地图。

+0

如何删除该地图中心的委托电话吗?你已经准备好了。 – Abizern 2012-03-09 16:49:06

回答

4

我认为它与iOS5来了,你现在可以删除委托的东西,只需设置MKMapView的userTrackingMode。将其设置为MKUserTrackingModeFollow,以便使用户随着用户移动,然后当他们开始平移地图时,它会自动关闭跟踪模式,然后您只需提供一个按钮即可将其重新打开。

+0

不正确..它仍然使用trackingmode技术更新地图 – 2013-10-09 23:57:43

+1

是的。当跟踪模式打开时,它会继续重新映射地图...直到您与之交互(禁用跟踪模式)。 OP要求的是什么以及为什么它被接受为正确的答案。 – Craig 2013-10-10 00:50:22

6

只有您第一次显示地图时才在中心位置。下面是一些伪代码...

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation  
    { 

     if(shouldCenterLocation){ 
      [mapView setCenterCoordinate:mapView.userLocation.location.coordinate animated:YES]; 
      shouldCenterLocation = FALSE; 

     } 
     //do all your other stuff here 
    } 

shouldCenterLocation是一个布尔标志,可以设置为TRUE首次地图所示,然后将其设置为FALSE,直到退出视图(或其他任何你必须显示中心位置)。

编辑:您可以用与处理按钮按下相同的方法来切换shouldCenterLocation的状态。

+3

请记住,您得到的第一个修复可能不是很准确,您可能需要在解决此问题之前检查水平精度是否够好。 – Craig 2012-03-09 19:56:10

1

在迅速3,我更喜欢用动画的方法:

mapView.setUserTrackingMode(.follow, animated: true) 

但设置属性不错的工作:

mapView.userTrackingMode = .follow 
相关问题