I was nearly convinced that this was just pure magic before talking to some people, then Googling this and reading about it. :)
So I was at my friend Sivanny's house last weekend and on the way home I was taking a bus and was just playing with my new iPod Touch. When it was announced last week I thought it was unfortunate that it didn't have a GPS unit in it, since often I am on the bus going somewhere and just want to know approx how long until I get to my destination (especially if I'm going somewhere I haven't been to before)... but, even without a GPS unit in the iPod Touch, it still WORKS?!?!??!?!!!!!!!!!!!!!!
Sure enough, I pressed the "Where am I now" button on Google Maps, and it showed me where the bus was, accurate within a block or so. Amazing.
Turns out this is triangulating WiFi hotspots, which is an interesting and novel idea, but how the heck does it know where the WiFi hotspots are when it's not connected to any of them?!?!?!?! This was pretty puzzling and I had to look it up.
So the result is that the iPod Touch uses a service called "WPS" (WiFi Positioning System) by a company called SkyHook. And they literally sent 500 people in vans around almost all major cities in the world over the past 5 years, collecting data about which WiFi router is in which location in the world. They have a huge database, and then the data is sent back to your iPod touch. Just awesome!!!!!!!!
Check out some more details here.