High precision positioning of UWB (ultra-wideband) in NLOS (non-line-of-sight) environment is one of the hot issues in the direction of indoor positioning. In this paper, a method of using a complementary Kalman filter (CKF) to fuse and filter UWB and IMU (inertial measurement unit) data and track the errors of variables such as position, speed, and direction is presented. Based on the uncertainty of magnetometer and acceleration, the noise covariance matrix of magnetometer and accelerometer is calculated dynamically, and then the weight of magnetometer data is set adaptively to correct the directional error of gyroscope. Based on the uncertainty of UWB distance observations, the covariance matrix of UWB measurement noise is calculated dynamically, and then the weight of UWB data observations is set adaptively to correct the position error. The position, velocity and direction errors are corrected by the fusion of UWB and IMU. The experimental results show that the algorithm can reduce the gyroscope deviation with magnetic noise and motion noise, so that the orientation estimates can be improved, as well as the positioning accuracy can be increased with UWB ranging noise.