3

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?

Stephen Bennett
  • 431
  • 6
  • 17

2 Answers2

11

Try:

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

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

David Berry
  • 40,941
  • 12
  • 84
  • 95
2

In addition to David Berry's answer, this lets you animate the zoom:

[self.mapView setVisibleMapRect:[self.mapView mapRectThatFits:circleOverlay.boundingMapRect] edgePadding:UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 5.0f) animated:YES];

Stewart Macdonald
  • 2,062
  • 24
  • 27