大家好我一直在 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/