将 MKCircle 半径转换为 CoreGraphics 圆弧半径
如何将 MKCircle 的半径(以米为单位)转换为可用于使用 MKOverlayPathView 子类中的核心图形绘制圆的值?
在下面的代码中,半径被硬编码为 50,但我需要它来反映 MKCircle 的半径。
对于位置,我使用 MKMapPointForCooperative() 将 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);
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?
In the following code the radius is hardcoded to 50 but I need it to reflect the radius of the 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MKCircle 的
boundingMapRect
的高度和宽度应等于圆的直径:The height and width of the MKCircle's
boundingMapRect
should be equal to the circle's diameter: