6

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!

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Sean R
  • 1,519
  • 2
  • 13
  • 16

3 Answers3

14

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.

Massimo Cafaro
  • 25,429
  • 15
  • 79
  • 93
  • 1
    For Google's sake: The headingAvailable property has been deprecated since iO4. There is now a headingAvailable class method that returns a boolean value. – Raj Jun 20 '11 at 19:04
3

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]];

François P.
  • 5,166
  • 4
  • 32
  • 31
  • Thanks, this was where I was getting really confused. I need to learn more about typedefs I guess. – Sean R Jun 28 '09 at 06:50
1

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

Sebastian Celis
  • 12,185
  • 6
  • 36
  • 44