WiFi fingerprinting remains a cornerstone of indoor localization, yet conventional KNN-based approaches suffer from high-dimensional noise and suboptimal parameter selection. While metaheuristic algorithms like GSA have been applied to optimize access point (AP) selection and K values, they often face high computational complexity in large-scale environments. This paper proposes SA-RLS-GSA-KNN, a novel two-stage optimization framework that integrates sparse-aware recursive least squares (SA-RLS) with the gravitational search algorithm (GSA) to optimize the parameters of KNN. First, SA-RLS with L1 regularization pre-screens critical APs by modeling RSS-position relationships, significantly reducing the search space. Second, GSA fine-tunes the final AP subset and optimal K value within this reduced space using a multi-objective fitness function balancing positioning error, feature count, and computational cost. The evaluation was conducted on 15 public datasets such as UJIIndoorLoc. The average positioning error achieved by SA-RLS-GSA was more than 20% lower than that of the baseline KNN algorithm.