gpt4 book ai didi

ios - map View 始终以我的位置为中心

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:53:39 25 4
gpt4 key购买 nike

我使用以下代码在用户按下按钮时获取我的位置

 [mapview setShowsUserLocation:YES];

然后执行以下操作以将 map 居中到用户的位置

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

我的问题是如何防止 map 始终以我的位置为中心?我想允许用户平移 map 。

最佳答案

仅在您第一次显示 map 时以该位置为中心。这是一些伪代码...

    - (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 是一个 bool 标志,您可以在第一次显示 map 时将其设置为 TRUE,然后将其设置为 FALSE 直到您退出 View (或显示中心位置的任何其他条件)。

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

关于ios - map View 始终以我的位置为中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9637737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com