iPhone 3.0 指南针:如何获取航向?

发布于 2024-07-25 21:25:45 字数 395 浏览 5 评论 0原文

我对 Objective-C 比较陌生,而且还不太了解它,所以我对这个可能非常业余的问题表示歉意。

我正在尝试从 CLHeading 和 CLLocationDirection 获取磁航向。 但是,我收到这行代码的编译错误:

locationLabel.text = [[[location course] magneticHeading] stringValue];

错误是:

warning: invalid receiver type 'CLLocationDirection'  
error: cannot convert to a pointer type

我真的不明白我在这里做错了什么。 请帮忙!

I'm relatively new to Objective-C and really don't know much about it yet, so I apologise for what is probably a really amateurish question.

I'm trying to get the magnetic heading from CLHeading and CLLocationDirection. However I'm getting compile errors for this line of code:

locationLabel.text = [[[location course] magneticHeading] stringValue];

The errors are:

warning: invalid receiver type 'CLLocationDirection'  
error: cannot convert to a pointer type

I don't really understand what I'm doing wrong here. Please help!

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

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

发布评论

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

评论(3

我是有多爱你 2024-08-01 21:25:45

以下是使用指南针所需的步骤。

1)检查可用性:如果位置管理器的headingAvailable属性为YES,则可以使用指南针。

2) 使用位置管理器方法 -(void) startUpdatingHeading 开始接收您正在搜索的信息

3) 使用委托方法实际检索此信息(不要忘记将自己设置为委托)

 - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

希望这有帮助。

Here are the steps needed to use the compass.

1) check the availability: if the headingAvailable property of the location manager is YES, then you can use the compass.

2) use the location manager method -(void) startUpdatingHeading to begin receiving the information you are searching for

3) actually retrieve this information using the delegate method (do not forget to set yourself as the delegate)

 - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

Hope this helps.

×眷恋的温暖 2024-08-01 21:25:45

MagneticHeading 是 CLLocationDirection 类型,它只是基本数据类型“double”的 typedef。 在您的示例中,您尝试向非对象的对象发送消息! 您应该像这样简单地格式化双精度数:

locationLabel.text = [NSString stringWithFormat:@"Heading %.3f", [[location course]MagneticHeading]];

magneticHeading is of CLLocationDirection type, which is simply a typedef for the primitive data type "double". In your example you are trying to send a message to something that is not an object ! You should simply format the double like so:

locationLabel.text = [NSString stringWithFormat:@"Heading %.3f", [[location course] magneticHeading]];

葬心 2024-08-01 21:25:45

您如何分配和初始化位置? 确保 location 定义为 (CLLocationDirection *) 而不仅仅是 (CLLocationDirection)

How are you allocating and initializing location? Make sure location is defined as a (CLLocationDirection *) and not just a (CLLocationDirection).

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