Localization is a key technology in wireless sensor networks (WSN). Many applications and middleware of WSN require the sensor nodes to obtain their locations. The accuracy of collected data can significantly be affected by an imprecise positioning of the event of interest. The main idea in most localization methods has been that some nodes with known coordinates (e.g., GPS-equipped nodes) transmit beacons with their coordinates in order to help other nodes to localize themselves. In this case, a fundamental research issue is the planning of the path that the mobile anchor should travel along. In this paper the authors study the path planning of the mobile anchor in localization for wireless sensor networks. Considering the graph theory, wireless sensor network is regarded as a connected undirected graph and then the path planning problem is translated into having a spanning tree and traversing graph. Breadth-first (BRF) and backtracking greedy (BTG) algorithms for spanning tree are proposed. The differences in performance between the two algorithms are analyzed. The BRF and BTG algorithms are effective and realistic algorithms that work in actual implementation. The simulations and real experiments show that these algorithms obtain higher localization precision and are robust in localization for the randomly deployment of the sensor nodes.