Location information is a key issue for applications of the Internet of Things. In this paper, we focus on mobile wireless networks with moving agents and targets. The positioning process is divided into two phases based on the factor graph, i.e., a prediction phase and a joint self-location and tracking phase. In the prediction phase, we develop an adaptive prediction model by exploiting the correlation of trajectories within a short period to formulate the prediction message. In the joint positioning phase, agents calculate the cooperative messages according to variational message passing and locate themselves. Simultaneously, the average consensus algorithm is employed to realize distributed target tracking. The simulation results show that the proposed prediction model is adaptive to the random movement of nodes. The performance of the proposed joint self-location and tracking algorithm is better than the separate cooperative self-localization and tracking algorithms.