This paper presents a path-planning strategy for unmanned aerial vehicles (UAVs) in urban environments with a ground risk map. The aim is to generate a UAV path that minimizes the ground risk as well as the flying cost, enforcing safety and efficiency over inhabited areas. A quantitative model is proposed to evaluate the ground risk, which is then used as a risk constraint for UAV path optimization. Subsequently, beetle swarm optimization (BSO) is proposed based on a beetle antennae search (BAS) that considers turning angles and path length. In this proposed BSO, an adaptive step size for every beetle and a random proportionality coefficient mechanism are designed to improve the deficiencies of the local optimum and slow convergence. Furthermore, a global optimum attraction operator is established to share the social information in a swarm to lead to the global best position in the search space. Experiments were performed and compared with particle swarm optimization (PSO), genetic algorithm (GA), firefly algorithm (FA), and BAS. This case study shows that the proposed BSO works well with different swarm sizes, beetle dimensions, and iterations. It outperforms the aforementioned methods not only in terms of efficiency but also in terms of accuracy. The simulation results confirm the suitability of the proposed BSO approach.