iosmkmapviewzoomingoverlaymkoverlay

MKMapView Zoom to Fit Overlays


I have an circle overlay on my MKMap, which the user can change the radius of. How can I make it so when the radius is changed the Map will automatically zoom to fit the new radius size.

I have tried:

_mapView.visibleMapRect = circleOverlay.boundingMapRect;

But it zooms in too far and the stroke around my circle overlay is cut off at the top and bottom. Can someone give me any help on how to fix this please?


Solution

  • Try:

    _mapView.visibleMapRect = [_mapView mapRectThatFits:circleOverlay.boundingMapRect];
    

    or even mapRectThatFits:edgePadding: to get a little extra space around the edges.