An important problem to be solved in smart city construction is how to improve the efficiency of mining frequent patterns that can be used for location prediction and location-based services of massive trajectory datasets. Owing to uncertain personal trajectory and non-explicit trajectory items, the existing sequence mining algorithms cannot be used directly. To solve this problem, this study proposes a distributed trajectory frequent pattern mining algorithm (SparkTraj) based on prefix pruning. First, a grouping and partitioning technique is used to abstract the original trajectory data and convert them into a common time series.Then, the generation of a redundant trajectory pattern is avoided by using the path adjacency pruning method. Second, to improve mining efficiency, SparkTraj is designed and implemented in Spark, which employs cluster memory computing. Finally, experiments on common datasets show that the proposed algorithm can effectively extract frequent trajectory patterns, and, in particular, deal with the massive amounts of trajectory data. Compared with common trajectory pattern mining algorithms, the SparkTraj algorithm not only improves the overall performance but also has good scalability.