Localization is an essential demand in wireless sensor networks (WSNs). It relies on several types of measurements. This paper focuses on positioning in 3-D space using time-of-arrival- (TOA-) based distance measurements between the target node and a number of anchor nodes. Central localization is assumed and either RF, acoustic or UWB signals are used for distance measurements. This problem is treated by using iterative gradient descent (GD), and an iterative GD-based algorithm for localization of moving sensors in a WSN has been proposed. To localize a node in 3-D space, at least four anchors are needed. In this work, however, five anchors are used to get better accuracy. In GD localization of a moving sensor, the algorithm can get trapped in a local minimum causing the track to deviate from the true path, thereby impairing real-time localization. The proposed algorithm is based on systematically replacing anchor nodes to avoid local minima positions. The idea is to form all possible combinations of five-anchor sets from a set of available anchor nodes (larger than five), and to segment the true path. Iterating through each segment, the sets of anchors that could draw the track to a local minimum are discarded and replaced with possible others to maintain the right track.