iPhone 3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是使用指南针所需的步骤。
1)检查可用性:如果位置管理器的
headingAvailable
属性为YES,则可以使用指南针。2) 使用位置管理器方法
-(void) startUpdatingHeading
开始接收您正在搜索的信息3) 使用委托方法实际检索此信息(不要忘记将自己设置为委托)
希望这有帮助。
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 for3) actually retrieve this information using the delegate method (do not forget to set yourself as the delegate)
Hope this helps.
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]];
您如何分配和初始化
位置
? 确保location
定义为(CLLocationDirection *)
而不仅仅是(CLLocationDirection)
。How are you allocating and initializing
location
? Make surelocation
is defined as a(CLLocationDirection *)
and not just a(CLLocationDirection)
.