Zoom MKMapView to fit polyline points

后端 未结 8 1231
小蘑菇
小蘑菇 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条回答
  • 2020-12-05 05:21
    -(void)zoomToPolyLine: (MKMapView*)map polyline: (MKPolyline*)polyline animated: (BOOL)animated
    {
        [map setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0) animated:animated];
    }
    
    0 讨论(0)
  • 2020-12-05 05:21

    Swift 3 version of garafajon excellent code

        if let first = self.mapView.overlays.first {
            let rect = self.mapView.overlays.reduce(first.boundingMapRect, {MKMapRectUnion($0, $1.boundingMapRect)})
            self.mapView.setVisibleMapRect(rect, edgePadding: UIEdgeInsets(top: 50.0, left: 50.0, bottom: 50.0, right: 50.0), animated: true)
        }
    
    0 讨论(0)
提交回复
热议问题