0

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]; 
};
honk
  • 9,137
  • 11
  • 75
  • 83
logixologist
  • 3,694
  • 4
  • 28
  • 46
  • can you please post full error message? Why are you taking "location" as a input when you are assigning it to userlocation coordinate? – chatur Jan 16 '12 at 11:12
  • Are you calling this method programmatically or is it hooked up to a button action in IB? If IB then this method doesn't have the correct signature for a button action method. If programmatically, show how you are calling it. –  Jan 16 '12 at 14:20
  • [MapView ZoomIn]: unrecognized selector sent to instance 0x8768200. I removed the passing in of location and it still breaks – logixologist Jan 16 '12 at 17:31
  • For a control action, the first parameter will be the control sending the message. If the action is linked to a button, the first parameter will be the UIButton regardless of what parameter type or name you give in the method. See [Cocoa Target-Action](http://developer.apple.com/library/ios/#documentation/general/conceptual/Devpedia-CocoaApp/TargetAction.html). –  Jan 16 '12 at 18:12

2 Answers2

0
-(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];  
}
Nagarjun
  • 6,557
  • 5
  • 33
  • 51
Ankit Goyal
  • 3,019
  • 1
  • 21
  • 26
0

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.

logixologist
  • 3,694
  • 4
  • 28
  • 46