我想获取当前位置并为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/

10-11 22:55
查看更多