Unable to Zoom with didUpdateUserLocation


As per the subject, testing on both the simulator and physical iPhone device has fail to zoom (I still see the blue dot is still as big as the size of Brazil). I implemented the code:

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
  CLLocationCoordinate2D loc = [userLocation coordinate];
  MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
  [worldView setRegion:region animated:YES];

When i put a break point on the line " CLLocationCoordinate2D loc = [userLocation coordinate]", i realised the execution has never reach this method. I suppose it means that the delegation has failed.

Any idea where should i look for problems?


Found the problem. when i re-read the same chapter again and again, i realise i did not link the delegate to the MKMapView in the xib file. When i like the delegate (under Referencing Outlets) to Map View, the Zoom works as per expected!


Good catch. I missed this too because it does not explicitly direct you to add this in the book. The book needs to either direct the reader to add it programmatically (like it did previously with the locationManager delegate) by adding the following code to application:didFinishLaunchingWithOptions:

Or in MainWindow.xib by dragging from Map View delegate to Whereami App Delegate like you mentioned.

This should probably be added under the Being a MapView Delegate section of the chapter since it is mentioned in passing: [quote]MKMapView has a delegate property that you set to be the instance of WhereamiAppDelegate.[/quote]

Looking further, the book technically does specify creating the delegate connections in Figure 5.4, but I would suggest adding some text to make this a little clearer, as I imagine a lot of readers will probably miss this as I did, since the focus in this section is on the interface properties (UITextField, UIActivityIndicatorView and MKMapView), and the delegates aren’t mentioned other than in the figure.


Yep - I missed this, too. Thanks for posting the solution - a good “duh!” moment for me…


great catch. One tip to check if your outlets are set is to make sure that in your WhereamiappDelegate.h file the circles next to your outlets are filled in.

Here’s another approach to setting your outlets.

  1. Add your objects to your view first.
  2. CTRL click on each object and then drag it into your header file.
  3. Select outlet and fill in the rest of the popover.