Coking plants are typical industrial pollution sites and may release heavy metals into the environment, posing a threat to human health. Scholars have discovered that different types of heavy metals are released during different coking production processes and lead to spatial differences in heavy metals. Research on the spatial distribution and driving factors of pollutants in the soil inside and outside coking plants is important for sampling design, risk assessment, pollution prevention and control, etc.. Inverse distance weight was used to analyze the spatial distribution of As, Cd, Cr, Cu, Hg, Ni, Pb, and Zn inside and outside of the coking plant. A geo-detector was used to find out the difference in the driving factors for the spatial distribution of heavy metals between soil from inside and outside the coking plant. The results showed that except As, Ni, and Zn, the overall background value rate of other heavy metals was above 50%, and the continuity of the spatial distribution of heavy metals in the soil was poor. The coefficient of variation (CV) exceeded 30%, representing a moderate variation. The average degree of CV inside the coking plant was Hg > Cd > As > Cu > Zn > Cr > Pb > Ni, and the external average degree of CV was Hg > Cu > Cd > As > Zn > Pb > Cr > Ni. An analysis of heavy metal content showed that the content of As, Cd, Cr, Pb, and Zn outside the coking plant was bigger than inside. According to geo-detector results, the physicochemical properties factors with a large contribution rate to the spatial distribution of heavy metals inside and outside the coking plant was the soil's total nitrogen, organic matter, and available medium-micro element content. Pollution source factors that contributed the most to the spatial distribution of heavy metals inside were the crude benzol and cold drum section, while the coke oven and quench section determined the outside spatial distribution of heavy metals. The q value of the strongest factor inside the coking plant was more than 0.5 while outside the coking plant it was less than 0.5. According to the interaction detector result, the interaction factors values of pollution sources and soil physicochemical properties to the inside spatial distribution of heavy metals was higher than outside. According to the distribution and geo-detector results, the strongest physicochemical properties driving factors that determined the inside and outside spatial distribution of heavy metals were relatively consistent. These factors were soil nutrient factors, which mainly influenced the availability of heavy metals. The differences in the production processes led to the difference between the inside and outside spatial distribution of heavy metals. The content of heavy metals outside the coking plant was higher than inside because the heavy metals came from various pollution sources. The driving forces for the distribution of heavy metals inside the plant were higher than outside and showed that the heavy metals inside of the plant were mainly from the coking plant. Heavy metal distribution inside the coking plant was mainly driven by the pollution source factor of the coking refining process and coking water, while heavy metal distribution outside the coking plant was mainly driven by the coking gas production process and other emission pollution source factors.