An inertial measurement unit-based pedestrian navigation system that relies on the intelligent learning algorithm is useful for various applications, especially under some severe conditions, such as the tracking of firefighters and miners. Due to the complexity of the indoor environment, signal occlusion problems could lead to the failure of certain positioning methods. In complex environments, such as those involving fire rescue and emergency rescue, the barometric altimeter fails because of the influence of air pressure and temperature. This paper used an optimal gait recognition algorithm to improve the accuracy of gait detection. Then a learning-based moving direction determination method was proposed. With the Kalman filter and a zero-velocity update algorithm, different gaits could be accurately recognized, such as going upstairs, downstairs, and walking flat. According to the recognition results, the position change in the vertical direction could be reasonably corrected. The obtained 3D trajectory involving both horizontal and vertical movements has shown that the accuracy is significantly improved in practical complex environments.