Setting the zoom level for a MKMapView

后端 未结 15 3095
不知归路
不知归路 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 05:58

    For Swift 3 it's pretty fast forward:

    private func setMapRegion(for location: CLLocationCoordinate2D, animated: Bool)
    {
        let viewRegion = MKCoordinateRegionMakeWithDistance(location, <#T##latitudinalMeters: CLLocationDistance##CLLocationDistance#>, <#T##longitudinalMeters: CLLocationDistance##CLLocationDistance#>)
        MapView.setRegion(viewRegion, animated: animated)
    }
    

    Just define the lat-, long-Meters and the mapView will fit the zoom level to your values.

提交回复
热议问题