Aiming at the problem that the detection of underground magnetic targets is greatly affected by the measurement accuracy and the recognition effect is not ideal, this paper proposes a magnetic target positioning method based on an adaptive whale optimization algorithm. As the whale optimization algorithm has problems such as easy to fall into local optima and slow convergence speed, this paper introduces two strategy improvements, simulated annealing (SA) and adaptive weighting (AW). Through 16 standard test functions, the improved whale optimization algorithm in this paper is compared with the standard whale optimization algorithm (WOA), particle swarm optimization algorithm (PSO), and cuckoo algorithm (CS). The results show that the improved whale optimization algorithm proposed in this paper It has higher optimization precision and faster convergence speed. Finally, the optimization algorithm in this paper is applied to the research of magnetic target positioning, and the effectiveness of the algorithm is verified through simulation experiments, and the accuracy of positioning the target is optimized.