CLLocationCooperative2D 不知道数组中有多少个?

发布于 2024-09-13 23:41:12 字数 554 浏览 4 评论 0原文

我需要使用如下内容构建一个数组:

CLLocationCoordinate2D  points[4];


    points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);

    points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066);

    points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);

    points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267);

问题是,我永远不会知道数组中有多少项,所以我可以指定计数。有没有办法创建一个 CLLocationCooperative2D 数组,并且只插入新坐标而不知道最终的总数是多少?

编辑:我的最终目标是使用坐标来制作 MKPolyline,使用需要 CLLocationCooperative2D 数组的 polylineWithCoordinates 方法。

I need to build an array using something like the following:

CLLocationCoordinate2D  points[4];


    points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);

    points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066);

    points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);

    points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267);

Problem is, I will never know how many items are going to be in the array, so I can specify the count. Is there a way to create a CLLocationCoordinate2D array, and just insert new coordinates without knowing what the final total will be?

EDIT: My final goal is to use the coordinates to make an MKPolyline, using the polylineWithCoordinates method which needs a CLLocationCoordinate2D array.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻梦旅人 2024-09-20 23:41:12
// unpacking an array of NSValues into memory
CLLocationCoordinate2D *points = malloc([mutablePoints count] * sizeof(CLLocationCoordinate2D));
for(int i = 0; i < [mutablePoints count]; i++) {
    [[mutablePoints objectAtIndex:i] getValue:(points + i)];
}

MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:points count:[mutablePoints count]];
free(points);
// unpacking an array of NSValues into memory
CLLocationCoordinate2D *points = malloc([mutablePoints count] * sizeof(CLLocationCoordinate2D));
for(int i = 0; i < [mutablePoints count]; i++) {
    [[mutablePoints objectAtIndex:i] getValue:(points + i)];
}

MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:points count:[mutablePoints count]];
free(points);
半步萧音过轻尘 2024-09-20 23:41:12

将它们放入 NSValue 对象中,然后将它们放入 NSMutableArray 中。

Box them up in an NSValue object and throw them in an NSMutableArray.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文