如何将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);
答案 0 :(得分:2)
MKCircle boundingMapRect
的高度和宽度应等于圆的直径:
CGRect boundingRect = [self rectForMapRect:circle.boundingMapRect];
CGFloat radius = boundingRect.size.width / 2;