Google has a big database of (hashes of) Wi-Fi network SSIDs. When Wi-Fi is enabled on your phone, it scans for Wi-Fi networks, and sends the list to Google (in a hashed form). In cities, networks are plentiful, and Wi-Fi networks are short-range, so the combination of networks it can 'see' gives a very accurate idea of where you are.
A similar thing happens with cellular network cell IDs, but these are spaced more widely apart. The phone itself can't perform triangulation, because it only has the received signal strength for each cell it can 'see': it doesn't know the signal's angle of arrival, the transmit strength of the cell, or what might be occluding the signal. However, it can still use the combination of which cells it can 'see' to estimate position, a little more accurately than the distance between cells.
Even if you're connected to an EDGE network, if Wi-Fi is enabled then the Wi-Fi scanning technique will still be used, so the location estimate will be more accurate.
Both these techniques are far less accurate than GPS, which computes a position based on time differences between signals coming from different satellites. When your device can 'see' enough satellites, the precision is limited mostly by deliberate interference added by the US government (which operates the system) to make it less useful to non-US armed forces.