iOS Question Corrected Magnetometer Values

stephane

Member
Licensed User
Longtime User
Hello,

I have tried the function GetMagnetometer in order to get the Magnetometer values.
It's look nice, nevertheless I would like to know how I can get the corrected values "CLHeading" & "CMCalibratedMagneticField".

upload_2015-9-7_11-2-20.png


According to the Apple docs - we have:
  • CMMagnetometer : Raw readings from the magnetometer
  • CMDeviceMotion (CMCalibratedMagneticField*) magneticField : Magnetometer readings corrected for device bias (onboard magnetic fields)
  • LHeading [x|y|z] : Magnetometer readings corrected for device bias and filtered to eliminate local external magnetic fields (as detected by device movement - if the field moves with the device, ignore it; otherwise measure it).
According the Objective C Code Example "Teslameter" from Apple :

// This delegate method is invoked when the location manager has heading data.
- (void)locationManager: (CLLocationManager *)manager didUpdateHeading: (CLHeading *)heading {
// Update the labels with the raw x, y, and z values.
self.xLabel.text = [NSString stringWithFormat: @"%.1f", heading.x];
self.yLabel.text = [NSString stringWithFormat: @"%.1f", heading.y];
self.zLabel.text = [NSString stringWithFormat: @"%.1f", heading.z];
}


Could you advice me (may be with Inline objective C Code) in order to get these values (CLHeading [x|y|z] and CMCalibratedMagneticField).

Thanks.

 

stephane

Member
Licensed User
Longtime User
Hello,

Thanks for the answer, unfortunately it doesn't work.

I have declared in the : Sub Process_Globals
Private LocManager As LocationManager

then start the process : LocManager.StartHeading
then I have written into a running function :

Dim no As NativeObject = LocManager
Dim heading As NativeObject = no.GetField("heading")
If heading.IsInitialized Then
Log(heading.GetField("x"))
End If

When I have compiled, I got this error message :

Application_Start
Application_Active
Application_Inactive
Error occurred on line: 65 (Main)
[<B4ILocationManager 0x170014250> valueForUndefinedKey:]: this class is not key value coding-compliant for the key heading.
Stack Trace: (
CoreFoundation <redacted> + 160
libobjc.A.dylib objc_exception_throw + 60
CoreFoundation <redacted> + 0
Foundation <redacted> + 276
Foundation <redacted> + 240
B4i Example -[B4INativeObject GetField:] + 160
B4i Example -[b4i_main _locmanager_headingchanged::] + 716
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 296
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1832
B4i Example -[B4IShell runMethod:] + 428
B4i Example -[B4IShell raiseEventImpl:method:args::] + 1176
B4i Example -[B4IShellBI raiseEvent:event: params:] + 1420
B4i Example +[B4IObjectWrapper raiseEvent:::] + 308
B4i Example -[B4ILocationManager locationManager:didUpdateHeading:] + 284
CoreLocation CLClientGetCapabilities + 22260
CoreLocation CLClientGetCapabilities + 5688
CoreLocation CLClientInvalidate + 864
CoreFoundation <redacted> + 20
CoreFoundation <redacted> + 312
CoreFoundation <redacted> + 1756
CoreFoundation CFRunLoopRunSpecific + 396
GraphicsServices GSEventRunModal + 168
UIKit UIApplicationMain + 1488
B4i Example main + 124
libdyld.dylib <redacted> + 4
)
 
Upvote 0
Top