2016-10-18 91 views
0

我不希望用户缩小更多。有没有办法使用swift在Map kit中设置最大缩放级别?使用swift的iOS地图中的最大缩放级别

+0

这可能是重复的吗?http://stackoverflow.com/questions/1636868/is-there-way-to-limit -mkmapview-maximum-zoom-level – Prav

+1

@Prav它在目标c中解释,但与swit没有关系。所以我发布这个问题 – Saranya

回答

5

请检查这是否符合您的条件。

import Foundation 
import MapKit 

class MapViewWithZoom: MKMapView { 

    var zoomLevel: Int { 
     get { 
      return Int(log2(360 * (Double(self.frame.size.width/256)/self.region.span.longitudeDelta)) + 1); 
     } 

     set (newZoomLevel){ 
      setCenterCoordinate(self.centerCoordinate, zoomLevel: newZoomLevel, animated: false) 
     } 
    } 

    private func setCenterCoordinate(coordinate: CLLocationCoordinate2D, zoomLevel: Int, animated: Bool){ 
     let span = MKCoordinateSpanMake(0, 360/pow(2, Double(zoomLevel)) * Double(self.frame.size.width)/256) 
     setRegion(MKCoordinateRegionMake(centerCoordinate, span), animated: animated) 
    } 
} 
+0

您的解决方案部分纠正 – Saranya

+1

您的解决方案部分正确,但是这种Int类型存在问题。例如,如果缩放级别为13.1至13.4,则舍入为13.因此,非常小的缩放无法完美运行 – Saranya

0

如何限制缩放级别:如果其他自定义地图叠加与较高maximumZ =使用

class CustomMapOverlay: MKTileOverlay { 

. 
init() { 
    self.minimumZ = 3 
    self.maximumZ = 15 
} 

}

或设定最低和在覆盖FUNC URL maximumZ值(forTilePath路径 。 17级别的话,那么这个17的值就会覆盖我们的15级的值。

相关问题