Traditional fingerprint localization algorithms need help with low localization accuracy, large data volumes, and device dependence. This paper proposes a LoRa-based improved fingerprint localization algorithm-particle swarm optimization-random forest-fingerprint localization for indoor localization. The first improvement step involves creating a new exceptional fingerprint value (referred to as RSSI-RANGE) by adding the Time of Flight ranging value (referred to as RANGE) to the Received Signal Strength Indication (RSSI) value and weighting them together. The second improvement step involves preprocessing the fingerprint data to eliminate gross errors using Gaussian and median filtering. After noise reduction, the particle swarm optimization algorithm is used to optimize the hyper parameters of the random forest algorithm, and the best RSSI-RANGE value is obtained using the random forest algorithm. The Kriging method is then used for interpolation to establish an offline fingerprint database, and the final online recognition and localization are performed. Experimental results demonstrate that the first improvement step improves localization accuracy by 53–57% in different experimental scenarios, while the second improves localization accuracy by 25–31%. When both steps are combined, the localization accuracy is improved by 58–63%. The effectiveness of this method is demonstrated through experiments.