Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone 3.0 Compass: how to get a heading?

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!

like image 443
Sean R Avatar asked Jun 25 '09 12:06

Sean R


1 Answers

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.

like image 138
Massimo Cafaro Avatar answered Sep 21 '22 02:09

Massimo Cafaro