Graphics Programs Reference
In-Depth Information
The documentation confirms that this is the method we need, so go ahead and implement
a stub for it in
WhereamiViewController.m
. The code completion should kick in
after a few keystrokes; make sure you choose the right method from the choices offered.
- (void)mapView:(MKMapView *)mapView
didUpdateUserLocation:(MKUserLocation *)userLocation
{
// Here we are... but how do we actually zoom?
}
Now that we know when to zoom, we can turn our attention to the problem of how. To
problem-solve in programming, it's best to start with the goal and what we already know.
The goal is to display a map that is zoomed in on the user's current location. We know
that when the
MKMapView
finds the user's location, it sends the message
mapView:didUpdateUserLocation:
to its delegate. We also know that, in the
mapView:didUpdateUserLocation:
method, a pointer to an
MKUserLocation
instance will be available.
In addition, we know from experience that the
MKMapView
does not automatically zoom
in when it finds the user's location, so it must be told to do so. This, of course, means that