如何在不使用didAddAnnotationViews的情况下缩小MKMapView?

时间:2012-01-16 10:24:54

标签: mkmapview mapkit mkcoordinateregion mkcoordinatespan

我正在尝试通过按钮找到放大和缩小的方法。如果我将代码放在方法didAddAnnotationViews中,它将完美地设置初始缩放。我尝试使用下面的代码更改缩放,但它继续崩溃说:

  

无法识别的选择器已发送到实例

我如何在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 个答案:

答案 0 :(得分:0)

我的问题是我试图在IBAction系列中传递MapView,这是我无法做到的。它不知道该怎么办。我在代码中引用了我的MapView,而不是试图在方法中传递它...

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];

你现在可以把它作为任何IBAction方法,它会放大到地图。

答案 1 :(得分: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];  
}