iOS MKMapView zoom to show all markers

前端 未结 5 839
梦如初夏
梦如初夏 2020-12-02 14:31

I\'m working with MKMapView and have plotted several points on the map. I have used the MKCoordinateRegion and MKCoordinateSpan to ena

5条回答
  •  被撕碎了的回忆
    2020-12-02 15:11

    It's an old question and I know you might not need any help. But I'm just putting it out there for anyone who is looking for a way to do this now as there's a new method in MKMapView as of iOS 7 that can be used. It is both clean and easy.

    Declaration

    SWIFT

    func showAnnotations(_ annotations: [AnyObject]!,
                animated animated: Bool)
    

    OBJECTIVE-C

    - (void)showAnnotations:(NSArray *)annotations
                   animated:(BOOL)animated
    

    Parameters

    annotations The annotations that you want to be visible in the map. animated YES if you want the map region change to be animated, or NO if you want the map to display the new region immediately without animations.

    Discussion

    Calling this method updates the value in the region property and potentially other properties to reflect the new map region.

提交回复
热议问题