Location-based services are widely used in mobile applications, which not only bring convenience, but also cause serious privacy concerns. Based on the characteristics of social network, this work proposes a cooperative protection architecture to model the relationship among users, communities and location-based service. Furthermore, in order to construct K anonymity set, a novel community structure-based trilateral Stackelberg game model is developed for K-anonymity protection. In addition, an optimization method based on the proposed model is designed by the backward induction process. Finally, the security and the performance under different situations such as the anonymity parameter K and the community structure parameter overlapping weights are analyzed. The analysis results indicate that the proposed model and the optimization method are effective for privacy protection and can achieve high secure in location-based services.