我想在按钮点击事件中显示mkcircle。我必须使用圆半径计算MKMapView的缩放级别以使圆圈明显。让半径变得小或大但是mkmapview上的mkcircle应该足够大,如下所示screenshot.My代码:
- (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];
//问题是圆圈看起来非常小而外部空间更多
任何建议将不胜感激。 谢谢!
答案 0 :(得分:0)
我知道它的旧帖子,但是可以通过任何方式回复。. 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)