Ios 地图套件缩放按钮

Ios 地图套件缩放按钮,ios,swift,mapkit,Ios,Swift,Mapkit,我的问题是关于一个地图服务我正在使用一个带有自定义平铺服务的地图现在我需要添加两个按钮或一个步进器来放大和缩小,我正在使用MapKit库。有人能帮忙吗?以下是swift 3的答案 用于放大 let region = MKCoordinateRegionMake(self.mapView.region.center, MKCoordinateSpanMake(mapView.region.span.latitudeDelta*0.7, mapView.region.span.longitudeDe

我的问题是关于一个地图服务我正在使用一个带有自定义平铺服务的地图现在我需要添加两个按钮或一个步进器来放大和缩小,我正在使用MapKit库。有人能帮忙吗?

以下是swift 3的答案

用于放大

let region = MKCoordinateRegionMake(self.mapView.region.center, MKCoordinateSpanMake(mapView.region.span.latitudeDelta*0.7, mapView.region.span.longitudeDelta*0.7))
mapView.setRegion(region, animated: true)
用于缩小

   let zoom = getZoom() // to get the value of zoom of your map.
   if zoom > 3.5{ // **here i have used the condition that avoid the mapview to zoom less then 3.5 to avoid crash.**

            let region = MKCoordinateRegionMake(self.mapView.region.center, MKCoordinateSpanMake(mapView.region.span.latitudeDelta/0.7, mapView.region.span.longitudeDelta/0.7))
            mapView.setRegion(region, animated: true)
        }
在这里,您可以获得地图视图的缩放程度

func getZoom() -> Double {

    var angleCamera = self.mapView.camera.heading
    if angleCamera > 270 {
        angleCamera = 360 - angleCamera
    } else if angleCamera > 90 {
        angleCamera = fabs(angleCamera - 180)
    }
    let angleRad = Double.pi * angleCamera / 180
    let width = Double(self.view.frame.size.width)
    let height = Double(self.view.frame.size.height)
    let heightOffset : Double = 20
    let spanStraight = width * self.mapView.region.span.longitudeDelta / (width * cos(angleRad) + (height - heightOffset) * sin(angleRad))
    return log2(360 * ((width / 256) / spanStraight)) + 1;
}
它对我有用。

查看答案

switch sender.tag {
    case 10:
    //Zoom In

        var region: MKCoordinateRegion = map_view.region
        region.span.latitudeDelta /= 2.0
        region.span.longitudeDelta /= 2.0
        map_view.setRegion(region, animated: true)
    case 20:

   //Zoom Out
        var region: MKCoordinateRegion = map_view.region
        region.span.latitudeDelta = min(region.span.latitudeDelta * 2.0, 180.0)
        region.span.longitudeDelta = min(region.span.longitudeDelta * 2.0, 180.0)
        map_view.setRegion(region, animated: true)
}

我有答案,但在客观的cThnx杜德它的工作牙NX杜德