0

I'm trying to get my MKMapView to zoom into to an annotation. I've tried all sorts however I remain zoomed out to my region.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    NSLog(@"Did add annotations");
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    MKCoordinateSpan span;
    span.longitudeDelta = 0.02;
    span.latitudeDelta = 0.02;
    MKCoordinateRegion region;

    region.center = mapView.userLocation.coordinate;
    region.span = span;

    [mapView selectAnnotation:mp animated:YES];
    [self.spotMapView setRegion:region animated:YES];
    [self.spotMapView regionThatFits:region];
}

Which does run, however the map stays zoomed out.

James
  • 5,137
  • 5
  • 40
  • 80
  • Why is the region.center being set to the userLocation instead of the annotation (mp)? –  Oct 26 '12 at 16:47
  • That's a good question. I'm not actually sure... I'll have to change that on Monday! – James Oct 27 '12 at 08:56

1 Answers1

0

Changing didAddAnnotationViews to this:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    NSLog(@"Did add annotations");
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    [mapView selectAnnotation:mp animated:NO];
}

Seemed to do the trick, the map now zooms in.

James
  • 5,137
  • 5
  • 40
  • 80