DeviceMotionData.fromJson constructor
Creates a new DeviceMotionData from a JSON
Implementation
factory DeviceMotionData.fromJson(Map<String, dynamic> json) {
MagneticFieldCalibrationAccuracy accuracy =
MagneticFieldCalibrationAccuracy.uncalibrated;
if (json['magneticFieldAccuracy'] == -1) {
accuracy = MagneticFieldCalibrationAccuracy.uncalibrated;
} else if (json['magneticFieldAccuracy'] == 0) {
accuracy = MagneticFieldCalibrationAccuracy.low;
} else if (json['magneticFieldAccuracy'] == 1) {
accuracy = MagneticFieldCalibrationAccuracy.medium;
} else if (json['magneticFieldAccuracy'] == 2) {
accuracy = MagneticFieldCalibrationAccuracy.high;
}
return DeviceMotionData(
Attitude(
Quaternion(json["quaternionX"], json["quaternionY"],
json["quaternionZ"], json["quaternionW"]),
json['pitch'],
json['roll'],
json['yaw']),
Gravity(json['gravityX'], json['gravityY'], json['gravityZ']),
RotationRate(
json['rotationRateX'], json['rotationRateY'], json['rotationRateZ']),
UserAcceleration(
json['accelerationX'], json['accelerationY'], json['accelerationZ']),
CalibratedMagneticField(
MagneticField(json['magneticFieldX'], json['magneticFieldY'],
json['magneticFieldZ']),
accuracy),
json['heading'],
);
}