以编程方式放大MKMapView [英] Zoom in a MKMapView programmatically
问题描述
我正在iPhone应用程序中使用MKMapView
.当我单击一个按钮时,缩放级别必须增加.这是我的第一种方法:
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 zoomIn = mapView.region;
zoomIn.span.latitudeDelta *= 0.5;
[mapView setRegion:zoomIn animated:YES];
但是,此代码无效,因为我没有更新longitudeDelta值.所以我添加了这一行:
However, this code had no effect, since I didn't update the longitudeDelta value. So I added this line:
zoomIn.span.longitudeDelta *= 0.5;
现在它可以工作,但仅在某些情况下可以. latitudeDelta
和longitudeDelta
不会以相同的方式更改,我的意思是,它们的值不成比例.知道如何解决这个问题吗?
Now it works, but only sometimes. The latitudeDelta
and longitudeDelta
don't change in the same way, I mean, their values are not proportional. Any idea how to solve this?
推荐答案
我不知道这是否是正确的方法,但是我正在使用它来放大和缩小.
I have no idea if this is the right way to do it, but I'm using this to zoom in and out.
case 0: { // Zoom In
//NSLog(@"Zoom - IN");
MKCoordinateRegion region;
//Set Zoom level using Span
MKCoordinateSpan span;
region.center=mapView.region.center;
span.latitudeDelta=mapView.region.span.latitudeDelta /2.0002;
span.longitudeDelta=mapView.region.span.longitudeDelta /2.0002;
region.span=span;
[mapView setRegion:region animated:TRUE];
}
break;
// Zoom Out
case 2: {
//NSLog(@"Zoom - OUT");
MKCoordinateRegion region;
//Set Zoom level using Span
MKCoordinateSpan span;
region.center=mapView.region.center;
span.latitudeDelta=mapView.region.span.latitudeDelta *2;
span.longitudeDelta=mapView.region.span.longitudeDelta *2;
region.span=span;
[mapView setRegion:region animated:TRUE];
}
这篇关于以编程方式放大MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!