Ship trajectory prediction plays an important role in various maritime applications. Although multiple time series models have been proposed to solve the problem of trajectory prediction, the inherent heterogeneity and multimodality of ship trajectories still pose many challenges, and there are high prediction errors in long-term trajectory prediction tasks. This article focuses on the practical application needs of long-term prediction of ship trajectories, A new discrete high-dimensional representation of AIS data and a new loss function were designed to model the prediction problem as a classification problem. A new model called TCNformer was constructed by combining temporal convolutional network (TCN) and transformer network, which effectively captures the long-term dependencies of AIS data using fused temporal and spatial features, To predict the position of the ship in the coming hours. The performance of the model proposed in this article was tested on a publicly available AIS dataset. Compared to other time series models, the predictive performance was improved by 2 times, and the longest prediction time range was extended by about 3.8 times, meeting the requirements for long-term prediction of ship trajectories.