SOLUTION 1:
Drag a UIButton to your UIViewController in the storyboard and connect it to an IBAction in the ViewController.m.
-(IBAction)zoomToUserLocation:(id)sender{
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[mapView setRegion:mapRegion animated: YES];
}
SOLUTION 2:
Or you can create your button programmatically like this:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(zoomToUserLocation)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"My Location" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
with the following method:
-(void)zoomToUserLocation{
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[mapView setRegion:mapRegion animated: YES];
}