Weighted Centroid Localization Algorithm: Theoretical Analysis and Distributed Implementation