The iPhone, starting with firmware 1.1.3, features a geopositioning system what works by triangulating on both cell towers and Wi-Fi access points. This produces approximate geographical coordinates that can be shown on a map.
To use this feature launch the Maps application, and tap the icon on the bottom-left corner of the screen.
Note that this features requires you to have an active wi-fi or EDGE connection (this is used to download the coordinates of the cell towers).
Check out this page on Wikipedia for more technical information about GSM localization.