Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didAddAnnotationViews not working on MKMapView

I've been playing around with the MKMapView and trying get my head around how the MKMapViewDelegate system works. So far I have no luck in getting the didAddAnnotationViews to get called when the current location marker is added.

I have set my app delegate to implement MKMapViewDelegate, I have an Outlet to the MapView in my xib and have set the delegate property of the MapView to be self, as in the app delegate instance. I have implemented didAddAnnotationViews in the app delegate which I simply NSLog any calls to it as shown below. The map is set to show current location which it does and adds the blue pin annotation on startup, but for some reason didAddAnnotationViews is not being hit.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
    NSLog(@"Annotation added!");
}

Any ideas what I might have missed?

like image 934
BenBtg Avatar asked Jan 29 '11 23:01

BenBtg


2 Answers

I came across the same issue in BNR. Here is what I ended up using:

    // Tell MKMapView to zoom to current location when found
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"didUpdateUserLocation just got called!");

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
    [mapView setRegion:region animated:YES];
}
like image 144
user656888 Avatar answered Sep 21 '22 12:09

user656888


mapView:didAddAnnotations: is only called in response to addAnnotation: or addAnnotations:. The users location pin will not trigger this delegate method.

like image 28
Mark Adams Avatar answered Sep 20 '22 12:09

Mark Adams