Zoom MKMapView to fit polyline points

后端 未结 8 1241
小蘑菇
小蘑菇 2020-12-05 04:39

I have an array, allCollections, that holds programmatically-created arrays of CLLocations the user has recorded through my iOS app. Each sub-array in allCollections holds a

8条回答
  •  旧时难觅i
    2020-12-05 05:05

    Swift 4 / slightly modified version of fundtimer's answer.

     func setVisibleMapArea(polyline: MKPolyline, edgeInsets: UIEdgeInsets, animated: Bool = false) {
        mapView.setVisibleMapRect(polyline.boundingMapRect, edgePadding: edgeInsets, animated: animated)
    }
    

    Calling the above using a route's polyline and leaving the default of not animated, and adding small edge insets of 10 all around:

    setVisibleMapArea(polyline: route.polyline, edgeInsets: UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0))
    

提交回复
热议问题