Due to environmental factors, the power-voltage (P-V) curve of a photovoltaic array's output characteristics often exhibits multiple peaks. Conventional maximum power point tracking (MPPT) algorithms are prone to getting trapped in local optima when attempting to track the maximum power point. Although the gravitational search algorithm (GSA) demonstrates better global search capabilities, it is still susceptible to local optima and often results in suboptimal MPPT performance. To address these issues and improve the search accuracy of the algorithm near the global optimum, this study introduces the particle swarm optimization (PSO) algorithm to optimize the parameters of GSA, while incorporating the Lévy flight step size to enhance global search ability. By fine-tuning the parameters of the PSO algorithm, the convergence speed is increased, enabling more effective tracking of the global maximum power point. Simulink modeling and simulation analysis demonstrate that, compared to traditional algorithms, the improved algorithm can identify the maximum power point of the photovoltaic array more quickly and stably, both under static and dynamic shading conditions.