ios系统地图中添加缩放功能

类似如下图功能:

组 1.jpg

1.自定义大头针,为了计算保存当前地图中心点

@property (nonatomic) MKCoordinateRegion region;

2.在滑动地图时拿到中心点,并保存

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    MKCoordinateRegion region;
    CLLocationCoordinate2D centerCoordinate = mapView.region.center;
    region.span = mapView.region.span;
    region.center= centerCoordinate;
    _region = region;
}
//button点击放大事件
- (void)addAct {
    CLLocationCoordinate2D centCoor = _region.center;
    MKCoordinateSpan span = MKCoordinateSpanMake(_region.span.latitudeDelta * 0.5, _region.span.longitudeDelta * 0.5);
    MKCoordinateRegion region = MKCoordinateRegionMake(centCoor, span);
    [self.mapView setRegion:region];
}
//button点击缩小事件
- (void)minAct {
    if (_region.span.latitudeDelta > 90) {
        return;
    }
    CLLocationCoordinate2D centCoor = _region.center;
    MKCoordinateSpan span = MKCoordinateSpanMake(_region.span.latitudeDelta * 2, _region.span.longitudeDelta * 2);
    MKCoordinateRegion region = MKCoordinateRegionMake(centCoor, span);
    [self.mapView setRegion:region];
}

单单看着就是一个很常见的功能,然而事实是网上类似功能的文章很少。希望这个例子对你有帮助。

你可能感兴趣的:(ios系统地图中添加缩放功能)