Cooperative Localization in Wireless Ad Hoc and Sensor Networks