Setting the zoom level for a MKMapView

后端 未结 15 2940
不知归路
不知归路 2020-12-02 05:46

I have a map which shows correctly, the only thing I want to do now is set the zoom level when it loads. Is there a way to do this?

Thanks

15条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 06:04

    Based on quentinadam's answer

    Swift 5.1

    // size refers to the width/height of your tile images, by default is 256.0
    // Seems to get better results using round()
    // frame.width is the width of the MKMapView
    
    let zoom = round(log2(360 * Double(frame.width) / size / region.span.longitudeDelta))
    

提交回复
热议问题