Localization is one of the critical services in Underwater Acoustic Sensor Networks (UASNs). Due to harsh underwater environments, the nodes often move with currents continuously. Consequently, the acoustic signals usually propagate with varying speeds in non-straight lines and the noise levels change frequently with the motion of the nodes. These limitations pose huge challenges for localization in UASNs. In this paper, we propose a novel localization method based on a variational filtering technique, in which the spatial correlation and temporal dependency information are utilized to improve localization performance. In the method, a state evolution model is employed to characterize the mobility pattern of the nodes and capture the uncertainty of the location transition. Then, a measurement model is used to reflect the relation between the measurements and the locations considering the dynamics of the acoustic speed and range noise. After that, a variational filtering scheme is adopted to determine the nodes’ locations, which consists of two phases: variational prediction and update. In the former phase, the coarse estimation of each node’ location is computed based on its previous location; in the latter phase, the coarse location is optimized by incorporating the measurements from the reference nodes as precisely as possible. At last, an iterative localization scheme is applied, in which a node labels itself as a reference node if the confidence of its location estimation is higher than the predefined threshold. We conducted extensive simulations under different parameter settings, and the results indicate that the proposed method has better localization accuracy compared to a typical SLMP algorithm while maintaining relatively high localization coverage. Moreover, spatial–temporal variational filtering (STVF) is more robust to the change of the parameter settings compared to SLMP.