我想在按钮单击事件中显示mkcircle。我必须使用圆半径来计算MKMapView的缩放级别,以使圆引人注目。让半径变小或变大,但mkmapview上的mkcircle应该足够大,如截图所示。码:

- (IBAction)showCircle:(id)sender {
    long radius=[self calculateRadius];
    NSLog(@"draw circle of radius=%ld",radius);
    MKCircle *circle= [[MKCircle alloc]init];
    circle = [MKCircle circleWithCenterCoordinate:CLLocationCoordinate2DMake([groupLat floatValue], [groupLon floatValue]) radius:radius];
    [myMapView addOverlay:circle];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake([groupLat floatValue], [groupLon floatValue]), 800, 800);

    //calculate zoom level
    double radius = [circle radius] + [circle radius] / 2;
    double scale = radius / 500;
    zoomLevel=(16 - log(scale) / log(2));

    region.span.latitudeDelta  =zoomLevel;
    region.span.longitudeDelta =zoomLevel;

    [myMapView setRegion:region animated:YES];

//问题是圆形看起来很小,外部空间更大

ios - 如何计算MKMapView的缩放级别以适合MKCircle?-LMLPHP
我想要像下面的输出

ios - 如何计算MKMapView的缩放级别以适合MKCircle?-LMLPHP

任何建议,将不胜感激。
谢谢!

最佳答案

我知道它的旧帖子,但是可以通过任何方式答复。.中的代码Swift 5 ,Xcode 11

let region = MKCoordinateRegion(circle.boundingMapRect)
mapView.setRegion(region, animated: true)
或者我们可以通过以下方式轻松添加一些余量
mapView.setVisibleMapRect(circle.boundingMapRect, edgePadding: UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50), animated: true)

10-07 22:33