DidAddAnnotationViews not working in MKMapView

I played with MKMapView and am trying to understand how the MKMapViewDelegate system works. So far I have been unlucky in the fact that makeAddAnnotationViews is called when the current location marker is added.

I set the application delegate to implement MKMapViewDelegate, I have an Outlet for MapView in my xib and set the delegate property of MapView as self, as in the instance of delegating the application. I implemented didAddAnnotationViews in the application’s dellet, which simply NSLog calls any calls, as shown below. The map is configured to display the current location that it is doing and adds a blue pin at launch time, but for some reason AdAdAnnotationViews doesn’t hit.

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

Any ideas what I could miss?

+6
ios objective-c mkmapview mkannotation
source share
3 answers

mapView:didAddAnnotations: is called only in response to addAnnotation: or addAnnotations: The user contact does not initiate this delegate method.

+3
source share

I ran into the same problem 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]; } 
+5
source share

I just want to confirm that I managed to get this job using

  - (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]; } 

Make sure you use mapView.delegate = self; or [mapView setDelegate: self];

0
source share

All Articles