The danger of downhole work is mainly due to the chemical toxic gases and flammable gases NO2, CO, SO2, H2S, CH4, CO2, etc. When the concentration reaches a certain value, it will produce very great harm. With the continuous development of sensor technology and communication technology, it is necessary to monitor the relevant geographic features below the ground. Because of the complex environmental parameters of the coal mine roadway and the interference caused by various electrical equipment, the transmission of mine electromagnetic signals will be affected, resulting in low positioning accuracy. However, the underground chemical gas leakage leads to the life of underground workers which cannot be guaranteed, so it is necessary to effectively monitor the concentration of chemical gas components in underground mines. In this paper, a moth flame algorithm based on optimized inertia weights is proposed. By continuously improving the local inertia weights, the global optimum is determined by using the change of inertia weights in the iterative process of the algorithm. By testing the convergence and optimal value of several algorithms under common test functions, IMFO can obtain the global optimal solution. Finally, the concentrations of chemical gases NO2, CO, SO2, H2S, CH4, and CO2 are monitored by setting specific areas to see if they reach the early warning values. Then, 16 coordinates in the region are used to predict the above method, and the IMFO algorithm can achieve the best prediction effect.