Timely and accurate traffic prediction has gained increasing importance for traffic management. This study proposes an improved k-nearest neighbor (KNN) model to enhance prediction accuracy with consideration of spatiotemporal correlation. This study tries to find more suitable nearest neighbors by adjusting the influence of time and space factors on the state matrix. Four different methods are tried in this study to weight the state matrix to improve distance measurement in KNN. The method using the Gaussian function to weight the time dimension and the correlation coefficient of the velocity series to weight the space dimension (KNN-GC) performs best. Compared to original KNN, the accuracy of KNN-GC increases by 8.21%. Besides, KNN-GC significantly improves the multi-step prediction accuracy and consistently outperforms the competing models when the prediction step is within 30 min. Consequently, the spatiotemporal weighted KNN method is promising in short-term traffic prediction.