将MKCircle Radius转换为CoreGraphics Arc Radius

时间:2011-11-27 18:50:15

标签: iphone ios core-graphics mapkit mkoverlay

如何将MKCircle的半径(以米为单位)转换为可用于在MKOverlayPathView子类中使用核心图形绘制圆的值?

在下面的代码中,半径硬编码为50,但我需要它来反映MKCircle的半径。

对于位置,我使用MKMapPointForCoordinate()将MKCircle的坐标转换为MKMapPoint,然后使用MKOverlayPathView的pointForMapPoint:将MKMapPoint转换为一个点。但是如何将MKCircle的半径转换为相对距离?

MKCircle *circle = [self circleForLocation:location]; 
CGPoint relativePoint = [self pointForMapPoint:MKMapPointForCoordinate(circle.coordinate)];
float radius = 50;

//Fill
[self applyFillPropertiesToContext:context atZoomScale:zoomScale];
CGContextAddArc(context, relativePoint.x, relativePoint.y, radius, 0, 2*3.1415926535898, 1);
CGContextDrawPath(context, kCGPathFill);

1 个答案:

答案 0 :(得分:2)

MKCircle boundingMapRect的高度和宽度应等于圆的直径:

CGRect boundingRect = [self rectForMapRect:circle.boundingMapRect];
CGFloat radius = boundingRect.size.width / 2;