为什么我的用户位置始终位于中心位置? [英] Why my user location is always in center?

查看:124
本文介绍了为什么我的用户位置始终位于中心位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有地图,我在地图打开时设置了中心用户位置. 我使用了以下代码:

i have a map in my app,i set the center user location when map is open. I have used this code:

 map.delegate=Self; 
 ......
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {

MKCoordinateRegion mapRegion;
mapRegion.center = self.mapView.userLocation.coordinate;
mapRegion.span = MKCoordinateSpanMake(0.5, 0.5); //Zoom distance
[self.mapView setRegion:mapRegion animated: YES];
}

但是当我移动地图时,它又回到了用户位置. 我该如何在没有关心用户位置的情况下自由地进入我的地图?

But when i move map it came back to user location. How can i move free into my map without care user location?

推荐答案

这是因为每次用户位置更改时,您都将重置位置.您应该只执行一次,例如

This is because you are resetting the location every time the user's location changes. You should do this only once, e.g.

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

    if (self.centerToUserLocation)
    {
        MKCoordinateRegion mapRegion;
        mapRegion.center = self.mapView.userLocation.coordinate;
        mapRegion.span = MKCoordinateSpanMake(0.5, 0.5); //Zoom distance
        [self.mapView setRegion:mapRegion animated: YES];
        self.centerToUserLocation = NO;
    }
}

centerToUserLocation类似于@property (nonatomic) BOOL centerToUserLocation

这篇关于为什么我的用户位置始终位于中心位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆