Promoted by the Internet of Thing era, the widespread use of mobile sensing devices equipped with positioning functions has led to the generation of substantial trajectory data. Mining and analyzing trajectory data has high research value, but poses a risk of user privacy leakage, resulting in fewer publicly available trajectory datasets for research and analysis. Therefore, a trajectory data publishing method that ensures high data utility while protecting user privacy has become a hot topic. In this paper, we propose a spatiotemporal trajectory data protection and publishing method based on kernel density estimation (STP-KDE), which protects the trajectory data and trajectory count values while improving data utility. In the protection process of trajectory data, we designed a kernel density clustering framework that is combined with the differential privacy exponential mechanism. In the protection process of trajectory counts value, the adaptive Laplace noise perturbation mechanism is proposed to differentially protect these counts. Experimental results show that STP-KDE can provide more useful data and stronger privacy protection than existing studies.