Sharing charging stations are an effective solution for daily usage of electric vehicles charging, however, the area with high demand cannot provide enough stations while there are plenty of stations left idle in remote areas with less demand. The core of the problem is the imbalance of demand and supply. In other word, we need to allocate the charging station to the appropriate locations to balance demand and supply. This study aims to solve the problem of locating charging stations for public electric vehicles (PUEVs), to improve the sharing charging level. We take into consideration the factors affecting charging station locations including mileage, PUEV distribution and passenger distribution. A Non-deterministic Polynomial (NP) model aiming to minimize the total vehicle service distance is developed. We use an agent-based model to simulate the optimized charging station location based on Anylogic. Through a case study of Beijing, we test the model in five situations. This paper concludes that priority, mileage, PUEV distribution and passenger distribution are the key factors affecting the location of PUEV charging stations, with exogenous variables such as the type of circuit and the voltage drawn as constants. The results of one situation show that the existing layout of the charging stations is unreasonable when charging frequency is sharply variant; this paper optimizes the existing location by improving the constraint for the smallest number of charging stations; the proposed model can be used for EV charging stations' location in densely populated metropolis.INDEX TERMS Agent, charging frequency, sharing charging, electric vehicles, location.