With the advancement of national urbanization, urban and rural construction have entered a brand new stage, and ecological civilization and circular economy have become the main themes of contemporary sustainable development. In this paper, the K-means clustering algorithm optimizes the spatial distribution of garden landscapes in urban parks from the perspective of a sponge city, with the ultimate goal of maximizing the comprehensive benefits of ecology, economy, and society. The case study of Yunlu Park in Yunshan Community, Fengze District, Quanzhou, is selected to elaborate on the design principles, structural characteristics, planning, and design methods of urban parks from the perspective of ecological cities. The results indicate that the K-means clustering method is capable of determining the optimal values for POI mixing degree and DPAT. The optimal values for POI mixing degree and DPAT are 4.2243 and 4.0415, respectively. Once these values reach their peak, they start to exhibit a mutual promotion relationship. This method reflects the spatial layout of parks and green spaces more accurately, and it has universal applicability. It can also provide a reference for the spatial layout research of other facilities. © 2024 Yu Chen., published by Sciendo.