I\'m using a MKMapView
inside an iPhone app. When I click a button the zoom level must increase. This is my first approach:
MKCoordinateRegion z
Here is my way to move map to the annotation point and zoom pretty close to it. You can easily change the zoom in line CGFloat newLatDelta = 0.06f;
- (void)moveMapToAnnotation:(MKPointAnnotation*)annotation
{
CGFloat fractionLatLon = map.region.span.latitudeDelta / map.region.span.longitudeDelta;
CGFloat newLatDelta = 0.06f;
CGFloat newLonDelta = newLatDelta * fractionLatLon;
MKCoordinateRegion region = MKCoordinateRegionMake(annotation.coordinate, MKCoordinateSpanMake(newLatDelta, newLonDelta));
[map setRegion:region animated:YES];
}
- (IBAction)btnZoomInPressed
{
MKCoordinateRegion region;
MKCoordinateSpan span;
region.center.latitude = lati;
region.center.longitude = longi;
span.latitudeDelta=viewMapSingleVenue.region.span.latitudeDelta /2.0002;
span.longitudeDelta=viewMapSingleVenue.region.span.longitudeDelta /2.0002;
region.span=span;
[viewMapSingleVenue setRegion:region animated:TRUE];
}
- (IBAction)btnZoomOutPressed
{
MKCoordinateRegion region;
MKCoordinateSpan span;
region.center.latitude = lati;
region.center.longitude = longi;
span.latitudeDelta=viewMapSingleVenue.region.span.latitudeDelta *2;
span.longitudeDelta=viewMapSingleVenue.region.span.longitudeDelta *2;
if(span.latitudeDelta < 200)
{
region.span=span;
[viewMapSingleVenue setRegion:region animated:TRUE];
}
}
In Swift 4.2
let location = mapView.userLocation
let region = MKCoordinateRegion(center: location.coordinate, span: MKCoordinateSpan(latitudeDelta: 50, longitudeDelta: 50))
mapView.setRegion(region, animated: true)