ボタンのクリックに対して、この Action zoomToCurrentLocation を試してください。getGotFix は、このコールバックによって設定されたフラグをチェックします
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
これがIBActionコードです(SOに重複があると確信しています)
- (IBAction)zoomToCurrentLocation:(id)sender
{
MKCoordinateRegion region;
if ([utils getGotFix] == YES)
{
region.center = self.mapView.userLocation.coordinate;
MKCoordinateSpan span;
span.latitudeDelta = 2; // Change these values to change the zoom 1 degree = 69 miles
span.longitudeDelta = 2;
region.span = span;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(region.center, 2*METERS_PER_MILE, 2*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
[mapView setRegion:adjustedRegion animated:YES];
}
else
{ // We dont yet have a user location fix so inform user
UIAlertView * timeoutAlert = [[UIAlertView alloc] initWithTitle:@"No location fix" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[timeoutAlert show];
}
}