The thing is a teacher of mine showed us an application that can show the location of a phone (within 1 - 2 km I think) just using the phone number, I asked him how was that possible and he said it uses triangulation to do that.
I'm just curious about it, it is really possible, I'm learning android programming and that sounds awesome, so I'm really interested in it. I really would like to know how it works.
I'm not a native English speaker. If you don't understand something you can ask me.
What you describe is not possible, except in specialized situations, such as:
The phone number in question is for some landline or other fixed-location phone, in some country where the location can be inferred from some digits of the number. For example, in the United States, you used to have a good idea where the phone was located based on area code and "exchange" (next three digits after the area code). In general, I would not expect this to give you "within 1 - 2 km" results, and it would not involve triangulation.
The user of the phone with the phone number is running some app on that phone that reports the phone's location to some server, and the app that your teacher ran is querying that server to find the location given a phone number. How the app on the user's phone determines its location would vary (GPS, cell tower triangulation, etc.). This approach has serious privacy implications, particularly if the user of the phone does not know that this app is publishing their location.
Your teacher has hacked into some system run by the mobile carrier, to query one of its servers that might have this location. If so, your teacher might get arrested, as this is illegal in some jurisdictions.
In general, it is not possible to find the location of a phone, given its number, for blindingly obvious privacy reasons.