SOLUZIONE 1:
Trascinare un UIButton al UIViewController nello storyboard e collegarlo a un IBAction nel 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];
}
SOLUZIONE 2:
Oppure è possibile creare il pulsante di programmazione come questo:
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];
con il seguente metodo:
-(void)zoomToUserLocation{
MKCoordinateRegion mapRegion;
mapRegion.center = mapView.userLocation.coordinate;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[mapView setRegion:mapRegion animated: YES];
}
fonte
2016-01-15 14:40:18
http://stackoverflow.com/questions/6169919/objective-c-mkmapview-center-on-user-location – Anil