演示效果,点击按钮实现地图显示的放大和缩小:
通过设置mapView的region属性,中心点不变,改变跨度 (地图的范围跨度 * 比例系数)
跨度变小,地图显示缩大
跨度变大,地图显示缩小
演示代码:
// 缩小
- (IBAction)zoomOutBtnClick:(UIButton *)sender {
//设置地图范围
//设置中心点为当前地图范围的中心点
CLLocationCoordinate2D center = self.mapView.region.center;
//设置跨度为当前地图范围的跨度 * 比例系数
MKCoordinateSpan span = MKCoordinateSpanMake(self.mapView.region.span.latitudeDelta * 2, self.mapView.region.span.longitudeDelta * 2);
//设置范围
[self.mapView setRegion:MKCoordinateRegionMake(center, span) animated:YES];
}
// 放大
- (IBAction)zoomInBtnClick:(UIButton *)sender {
// 设置范围
// 设置中心点
CLLocationCoordinate2D center = self.mapView.region.center;
// 设置跨度 : 跨度变小,地图显示缩大 (地图的范围跨度 * 比例系数)
MKCoordinateSpan span = MKCoordinateSpanMake(self.mapView.region.span.latitudeDelta * 0.5, self.mapView.region.span.longitudeDelta * 0.5);
//设置地图范围
[self.mapView setRegion:MKCoordinateRegionMake(center, span) animated:YES];
/**
*
typedef struct {
CLLocationCoordinate2D center; 中心点 确定地图的位置
MKCoordinateSpan span; 经纬度跨度 确定地图的大小
} MKCoordinateRegion;
*/
/**
*
typedef struct {
CLLocationDegrees latitudeDelta; 纬度跨度 1°=111km
CLLocationDegrees longitudeDelta; 经度跨度
} MKCoordinateSpan;
*/
}