Localization in wireless sensor networks (WSNs) is an essential service, important as both a goal and a mean. It is a goal for WSNs in order to label reported data and a mean for most WSNs to implement networks management services. In distributed localization, there could be a small number of nodes, which have a priori knowledge about their position, called reference nodes and most of the other nodes which do not know their location. Range-free localization technique is the cost-effective technique because it does not require sensors to be equipped with any hardware, but use less information than range-based algorithm. Centroid algorithm is one of the range-free technique, where the references send out their position information to neighbor nodes at periodic intervals. The position of unknown node is then estimated to be centroid of the reference nodes. In this paper, we propose the improved centroid algorithm by selecting the neighbor references based on the connectivity of unknown node and them. Simulation results show that the localization error of unknown nodes is reduced by the proposed method.