My iPod Touch doesn’t have a GPS receiver, so the only way it knows my location is by looking up the detected WiFi networks in a database. The first and most famous such database is Skyhook, and Apple used to use them, but last year they parted ways, and Apple switched to an in-house database.
How do these databases know how to map WiFi networks to geographic location? Well, you can imagine driving a vehicle all over the place, like Google StreetView. In fact, the Googlemobile did detect wireless networks, and got in trouble for collecting a bit more data than was necessary. But I’m sure that kind of survey is one source of data.