如何设置 MKMap 视图的缩放级别使 MKCircle(可变半径)可见?

How to set the zoom level of the MKMap view making MKCircle(varying radius) visible?

我的地图视图包含一个圆圈,该圆圈以一个中心覆盖许多精确点 point.Whenever 用户单击一个按钮,地图应该放大到圆圈这样的级别 visible.The 地图不应该缩放或多或少它应该显示确切的 circle.When 用户注销然后圆将在下一个 login.How 中有新的半径来计算适当的缩放级别。 我的代码:

-(void)showCircle{

   //calculate new radius
    long radius=[self calculateRadius];
    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);
    MKCoordinateSpan span;

    //calculate zoom level
    double radius=[circle radius]);
    double rad = radius + radius / 2;

    double scale = rad / 500;
    zoomLevel=(16 - log(scale) / log(2));

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

    [myMapView setRegion:region animated:YES];
}

提前致谢!

你可以试试:mapRectThatFits(:) or mapRectThatFits(:edgePadding:)

可能是这样的,根据你的圈子缩放地图:

myMapView.visibleMapRect = [myMapView mapRectThatFits:circle.boundingMapRect];

希望对您有所帮助:)