iphone - MKMapView 无法按位置设置居中

标签 iphone ios mkmapview cllocationmanager mkannotation

我想获取当前位置并在 MKMapView 上为该坐标设置动画。我得到了当前位置,但我没有在 MKMapView 上对这个位置进行动画处理。如何使用蓝点动画显示当前位置?

- (void)viewDidLoad
{
    [super viewDidLoad];

    locationManager = [[CLLocationManager alloc] init];

    self.mapView.delegate = self;
    [self.mapView setShowsUserLocation:YES];

    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    locationManager.distanceFilter=kCLDistanceFilterNone;

    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{

    location = [locationManager location];

    CLLocationCoordinate2D coord;
    coord.longitude = location.coordinate.longitude;
    coord.latitude = location.coordinate.latitude;
    lat = coord.latitude;
    longt = coord.longitude;

    [self.mapView setCenterCoordinate:coord animated:TRUE];
}

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views

{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id<MKAnnotation> mp = [annotationView annotation];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate] ,250,250);
    [mv setRegion:region animated:YES];
}

最佳答案

self.mapView.userTrackingMode = MKUserTrackingModeFollow

这将在用户位置后面加上一个蓝点,这似乎是你想要实现的

关于iphone - MKMapView 无法按位置设置居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15565569/

相关文章:

iphone - 修复了背景图片在 iPad 和 iPhone 上无法正常工作的问题

iphone - UISearchDisplayController 和大量数据的搜索性能

iphone - AVPlayer 反向播放

objective-c - 创建导航IOS APP

ios - NSNumberFormatter setFormat 错误

ios - 下拉并按住时 UIRefreshcontrol 抖动

ios - 如何防止在 IOS 中加载整个 map

iphone - 如何快速检查 NSString 对象是否是有效的 url?

swift - 放下图钉并从用户在 map 上点击的位置获取地址

objective-c - MKMapView 中 userLocation 的中心区域