To address the problem that anchor ratio had a strong impact on localization error and coverage in centroid algorithm in wireless sensor network (WSN), an improved algorithm was proposed. This algorithm differentiated the priority of the unknown nodes according to the distance between unknown nodes and anchors. The algorithm was proposed to locate the unknown nodes with the highest priority, and then update them to new anchors. Finally, the rest unknown nodes are located by centroid algorithm. The simulation results show that this improved algorithm can effectively reduce the localization error and enhance the coverage when the anchor ratio is lower.