将值数组放入 CLLocationCooperative2D 的优雅方法

发布于 2024-12-31 22:36:39 字数 906 浏览 5 评论 0原文

是否有一种优雅的方法从 NSDecimalNumber 值数组创建 CLLocationCooperative2D 对象?也许是一个递归函数?

我是目标 C 的新手,对此遇到困难。

下面是我正在使用的数据结构的示例。


NSDecimalNumber 值的数组:

NSLog(@"path: %@", [path description]);

返回

path: (
    "-71.4826609644423",
    "27.7231737704478",
    "-71.4826608497223",
    "27.7231120144099",
    "-71.4826391681679",
    "27.7228678610506",
    ...
    "-71.482414263977",
    "27.7225217655116",
)

我可以像这样手动创建 CLLocationCooperative2D 对象:

CLLocationCoordinate2D pathCoords[5]={
    CLLocationCoordinate2DMake(27.7231737704478,-71.4826609644423),
    CLLocationCoordinate2DMake(27.7231120144099,-71.4826608497223),
    CLLocationCoordinate2DMake(27.7228678610506,-71.4826391681679),
    ...
    CLLocationCoordinate2DMake(27.7225217655116,-71.482414263977),
};

欢迎任何编码建议。 谢谢!

Is there an elegant way to create a CLLocationCoordinate2D object from an array of NSDecimalNumber values? Perhaps a recursive function?

I'm new to objective C and am having difficulty with this.

Below is an example of the data structures I'm working with.


an array of NSDecimalNumber values:

NSLog(@"path: %@", [path description]);

returns

path: (
    "-71.4826609644423",
    "27.7231737704478",
    "-71.4826608497223",
    "27.7231120144099",
    "-71.4826391681679",
    "27.7228678610506",
    ...
    "-71.482414263977",
    "27.7225217655116",
)

I can manually create the CLLocationCoordinate2D object like this:

CLLocationCoordinate2D pathCoords[5]={
    CLLocationCoordinate2DMake(27.7231737704478,-71.4826609644423),
    CLLocationCoordinate2DMake(27.7231120144099,-71.4826608497223),
    CLLocationCoordinate2DMake(27.7228678610506,-71.4826391681679),
    ...
    CLLocationCoordinate2DMake(27.7225217655116,-71.482414263977),
};

Any coding suggestions are welcome.
Thanks!

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

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

发布评论

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

评论(2

热鲨 2025-01-07 22:36:39

我假设您已经创建了一个名为 pathCoordsCLLocationCooperative2D 结构,大小为 5。

for(int i=0;i<[path count]/2;i++)
   pathCoords[i] = CLLocationCoordinate2DMake([path objectAtIndex:2*i+1], [path objectAtIndex:2*i]);

您的问题的本质不是递归的,因此如果您采用递归,那就太过分了。

I'm assuming you have already created a CLLocationCoordinate2D structure called pathCoords of size 5.

for(int i=0;i<[path count]/2;i++)
   pathCoords[i] = CLLocationCoordinate2DMake([path objectAtIndex:2*i+1], [path objectAtIndex:2*i]);

The nature of your problem is not recursive, so if you go recursive - it's an overkill.

凌乱心跳 2025-01-07 22:36:39

最终的解决方案包括将 NSDecimalNumbers 类型转换为 doubleValues:

for(int i=0; i<[path count]/2; i++) {
        pathCoords[i] = CLLocationCoordinate2DMake([[path objectAtIndex:2*i+1] doubleValue], [[path objectAtIndex:2*i] doubleValue]);

The final solution including typecasting the NSDecimalNumbers to doubleValues:

for(int i=0; i<[path count]/2; i++) {
        pathCoords[i] = CLLocationCoordinate2DMake([[path objectAtIndex:2*i+1] doubleValue], [[path objectAtIndex:2*i] doubleValue]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文