Aiming at the problems of poor location accuracy caused by the harsh and complex underground environment, long strip roadway, limited wireless transmission and sparse anchor nodes, an underground location algorithm based on Random Forest and environmental factors compensation is proposed. Firstly, the network model of underground wireless access point (AP) and tunnel environment are analyzed, and the fingerprint location algorithm is constructed. Meanwhile, the Received Signal Strength (RSS) is analyzed by Kalman Filter algorithm in the offline sampling and real-time positioning stage. In the real-time positioning stage, random forest algorithm and signal intensity ratio compensation algorithm are used to optimize the situation that the location error fluctuates greatly in the near area. Meanwhile, the target speed constraint condition is introduced to reduce the error caused by environmental factors. The experimental results show that the algorithm proposed in this paper solves the problem of insufficient location accuracy and large fluctuation affected by environment when the anchor nodes are sparse. The average location accuracy reaches three meters, which can satisfy the application of underground rescue, activity track playback, disaster monitoring and positioning, and has high application value in complex underground environment.Aiming at the problems of poor location accuracy caused by the harsh and complex underground environment, long strip roadway, limited wireless transmission and sparse anchor nodes, an underground location algorithm based on Random Forest and environmental factors compensation is proposed. Firstly, the network model of underground wireless access point (AP) and tunnel environment are analyzed, and the fingerprint location algorithm is constructed. Meanwhile, the Received Signal Strength (RSS) is analyzed by Kalman Filter algorithm in the offline sampling and real-time positioning stage. In the real-time positioning stage, random forest algorithm and signal intensity ratio compensation algorithm are used to optimize the situation that the location error fluctuates greatly in the near area. Meanwhile, the target speed constraint condition is introduced to reduce the error caused by environmental factors. The experimental results show that the algorithm proposed in this paper solves the problem of insufficient location accuracy and large fluctuation affected by environment when the anchor nodes are sparse. The average location accuracy reaches three meters, which can satisfy the application of underground rescue, activity track playback, disaster monitoring and positioning, and has high application value in complex underground environment.