Convert MKCircle Radius to CoreGraphics Arc Radius

人盡茶涼 提交于 2019-12-06 12:39:59

问题


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);

回答1:


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;


来源:https://stackoverflow.com/questions/8288093/convert-mkcircle-radius-to-coregraphics-arc-radius

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!