-->

iPhone 3.0指南针:如何让一个标题?(iPhone 3.0 Compass: how to

2019-06-24 03:25发布

我是比较新的Objective-C和真的不很了解,所以我什么可能是一个非常业余的问题道歉。

我想从CLHeading和CLLocationDirection磁航向。 但是我得到的编译错误此行的代码:

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

的错误是:

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

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

Answer 1:

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

1)检查可用性:如果headingAvailable外景经理的属性是YES,那么你可以使用指南针。

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

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

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

希望这可以帮助。



Answer 2:

magneticHeading是CLLocationDirection类型,这是简单地对基本数据类型的“双”一个typedef的。 在您的例子中,你正试图将消息发送到的东西是不是一个对象! 您应该简单地格式化,像这样的双:

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



Answer 3:

你是如何分配和初始化location ? 确保location被定义为(CLLocationDirection *)而不仅仅是一个(CLLocationDirection)



文章来源: iPhone 3.0 Compass: how to get a heading?