Question

from Apple's Documentation :

@property(readonly, nonatomic) CMMagneticField magneticField

Returns the magnetic field measured by the magnetometer. (read-only)

The value of this property is the total magnetic field observed by the device which is equal to the Earth’s geomagnetic field plus bias introduced from the device itself and its surroundings.

@property(readonly, nonatomic) CMCalibratedMagneticField magneticField

The CMCalibratedMagneticField returned by this property gives you the total magnetic field in the device’s vicinity without device bias. Unlike the magneticField property of the CMMagnetometer class, these values reflect the earth’s magnetic field plus surrounding fields, minus device bias.

Which of the two do I need to use if I want to get the device's deviation from the North in degrees? That is,the value a digital compass on the iPhone would display, based on where the device is facing (e.g. 90, 180, 193, etc..)

I know that none of the above return degrees in integer format. The documentation is not clear as to what exactly they return.. I think it's MicroTeslas..

But if they do return a MicroTesla value how do I convert this value into an integer representing degrees? Do I have to multiply that MicroTesla value with some constant or something of that nature?

Thanks for any help!

Was it helpful?

Solution

You need to measure the device heading which you get from CLLocationManager. Heres how you start getting the heading updates (first import core Location framework) -

if([CLLocationManager headingAvailable]) //check if device has magnetometer
    [locationManager startUpdatingHeading];

after this you get updates in this delegate -

- (void)locationManager:(CLLocationManager*)manager 
       didUpdateHeading:(CLHeading*)newHeading
{
    // If the accuracy is valid, process the event.
    if (newHeading.headingAccuracy > 0)
        CLLocationDirection theHeading = newHeading.magneticHeading;

    return;
}

so CLLocationDirection represents a direction that is measured in degrees relative to true north.

Direction values are measured in degrees starting at due north and continue clockwise around the compass. Thus, north is 0 degrees, east is 90 degrees, south is 180 degrees, and so on. A negative value indicates an invalid direction.

hopt his helps...

UPDATE: do check out these links - CLLocationManager and degrees of heading in iPhone and iPhone 3.0 Compass: how to get a heading? and apple reference.

OTHER TIPS

As a side note, if you want to get the magnetic declination for your current position you can simply subtract the magnetic heading from the true heading. The number is useful for converting magnetic compass bearings to true north bearings.

CLLocationDirection magneticDeclination = newHeading.trueHeading - newHeading.magneticHeading;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top