首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将MKCircle半径转换为CoreGraphics圆弧半径

将MKCircle半径转换为CoreGraphics圆弧半径
EN

Stack Overflow用户
提问于 2011-11-28 02:50:15
回答 1查看 773关注 0票数 1

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

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

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

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-28 03:46:03

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

代码语言:javascript
复制
CGRect boundingRect = [self rectForMapRect:circle.boundingMapRect];
CGFloat radius = boundingRect.size.width / 2;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8288093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档