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 all the location points in a trip taken.
I draw MKPolylines off of the CLLocations in the arrays in allCollections to represent those trips on an MKMapView. My question is this: With the polylines added to the map, how would I go about programmatically zooming and centering the map to display all of them?
@Fundtimer pointed it right way, Only thing is that Padding needs to be adjusted as per visual needs, that way it will support all the other overlays and following is the generic solution for all overlays.
Swift 3 version of garafajon excellent code
in swift:
this will zoom/pan to fit all overlays with a little buffer
Swift 4 / slightly modified version of fundtimer's answer.
Calling the above using a route's polyline and leaving the default of not animated, and adding small edge insets of 10 all around: