How do I obtain the height of the terrain through longitude and latitude?

It depends on what you mean by “height” of the terrain. Do you need the height of the terrain relative to the WGS84 ellipsoid? Or do you need the height of the terrain above sea level?

In any case, here are a couple of forum threads with similar questions. They may be applicable to your use case.