objective-c - 如何从点数组创建 CGPathRef

标签 objective-c ios5 mapkit

大家好我一直在 map 应用程序中工作,我需要在两个位置之间绘制路线,我也有路线坐标(使用 google Direction api)并将其保存在一个数组中,现在我只需要要做的是从点数组创建路径,稍后我将使用带有 MKOverlayPathView 的路径在 map 上创建真实路线。我的问题是如何从坐标数组创建 CGPathRef,或者以任何其他方式执行相同操作
提前致谢

最佳答案

假设坐标作为 NSValue 对象存储在 NSArray 中,您可以执行以下操作:

CGMutablePathRef path = CGPathCreateMutable();
if (points && points.count > 0) {
    CGPoint p = [(NSValue *)[points objectAtIndex:0] CGPointValue];
    CGPathMoveToPoint(path, nil, p.x, p.y);
    for (int i = 1; i < points.count; i++) {
        p = [(NSValue *)[points objectAtIndex:i] CGPointValue];
        CGPathAddLineToPoint(path, nil, p.x, p.y);
    }
}
// do stuff
CGPathRelease(path);

关于objective-c - 如何从点数组创建 CGPathRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9309930/

相关文章:

objective-c - 在 Objective-C 中读取 .strings 文件?

iphone - 如何更改搜索栏的颜色?

ios - NSFetchedResultsController 在排序时检索特定数据

objective-c - 动态更改 Popover View 框架

xcode - 使用 iOS5 的 Storyboard时如何设计 UIScrollView 的 subview ?

objective-c - 使用 Mapkit 和谷歌地图在 iPhone 中进行 GPS 路由(最短路径)

ios - MKLocalSearch 没有找到明显的结果

objective-c - 应用程序正在运行时 gpus_ReturnNotPermissionKillClient "backgrounded"

iphone - XCode base_convert

ios - 如何快速删除标记的 "trace"