将MKCircle Radius转换为CoreGraphics Arc Radius [英] Convert MKCircle Radius to CoreGraphics Arc Radius
问题描述
如何将MKCircle的半径(以米为单位)转换为可用于在MKOverlayPathView子类中使用核心图形绘制圆的值?
How can I convert an MKCircle's radius (in meters) into a value I can use to draw a circle using core graphics in an MKOverlayPathView subclass?
以下代码半径硬编码为50,但我需要它来反映MKCircle的半径。
In the following code the radius is hardcoded to 50 but I need it to reflect the radius of the MKCircle.
对于位置,我使用MKMapPointForCoordinate()将MKCircle的坐标转换为MKMapPoint ,然后使用MKOverlayPathView的pointForMapPoint:将MKMapPoint转换为一个点。但是如何将MKCircle的半径转换为相对距离?
For the position I use MKMapPointForCoordinate() to convert the MKCircle's coordinate to an MKMapPoint, then convert the MKMapPoint to a point using MKOverlayPathView's pointForMapPoint:. But how can I convert the MKCircle's radius into a relative distance?
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);
推荐答案
MKCircle的高度和宽度 boundingMapRect
应该等于圆的直径:
The height and width of the MKCircle's boundingMapRect
should be equal to the circle's diameter:
CGRect boundingRect = [self rectForMapRect:circle.boundingMapRect];
CGFloat radius = boundingRect.size.width / 2;
这篇关于将MKCircle Radius转换为CoreGraphics Arc Radius的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!