How to zoom out of an MKMapView without using didAddAnnotationViews?

1.3k views Asked by At

I am trying to find a way to do a zoom in and out via a button. If I put code within the method didAddAnnotationViews, it will set the initial zoom perfectly. I tried to get the zoom to change with the code below, but it keeps on crashing saying:

Unrecognized Selector sent to Instance

How can I run this in an IBAction?

-(IBAction)ZoomIn:(MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mv centerCoordinate:(CLLocationCoordinate2D)location
{
   MKCoordinateRegion region;
   MKCoordinateSpan span; 
   span.latitudeDelta=0.05;
   span.longitudeDelta=0.05;
   location = mv.userLocation.coordinate;
   location = mv.userLocation.location.coordinate;
   region.span=span;
   region.center=location;
   [mv setRegion:region animated:TRUE];
   [mv regionThatFits:region]; 
};
2

There are 2 answers

0
logixologist On

My issue was that I was trying to pass in the MapView in the IBAction line which I couldnt do. It did not know what to do with it. I referenced my MapView in the code instead of trying to pass it in the method...

CLLocationCoordinate2D location;
MKCoordinateRegion region;
MKCoordinateSpan span; 
span.latitudeDelta=1.00;
span.longitudeDelta=1.00;
location = self.myMap.userLocation.coordinate;
location = self.myMap.userLocation.location.coordinate;
region.span=span;
region.center=location;
[self.LightUpMap setRegion:region animated:TRUE];
[self.LightUpMap regionThatFits:region];

You can put this is any IBAction method now and it will zoom in to the map.

0
Ankit Goyal On
-(void)zoomOut:btnMinus
{
  MKCoordinateSpan span = mapView.region.span;
  span.latitudeDelta = span.latitudeDelta * 2;
  span.longitudeDelta = span.longitudeDelta * 2;
  region.span=span;
  [mapView setRegion:region animated:YES];
  for(int j=2;j<count;j++)
  { places[j]=1;}
  [self filterAnnotations];  
}