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. And then the Received Signal Strength (RSS) is analyzed by Kalman Filter algorithm in the offline sampling and real-time positioning stage. Meanwhile, the target speed constraint condition is introduced to reduce the error caused by environmental factors. The experimental results show that the algorithm proposed solves the problem of insufficient location accuracy and large fluctuation affected by environment when the anchor nodes are sparse. At the same time, the average location accuracy reaches three meters, which can satisfy the application of underground rescue, activity track playback, disaster monitoring and positioning. It has high application value in complex underground environment.