Calculating the Accurate Length of a Clamped-to-Ground Polyline

Is there a way to determine the length of a two-point polyline that has clampToGround = true? This is because its length differs from the straight-line distance between the points it encompasses, as it accounts for the complete path including terrain elevation variations.

I have searched for information and haven’t found anything.

The only thing that comes to mind is to sample the terrain and use sampleTerrainMostDetailed to get the height of intermediate points and then measure the distances between these points and sum them all up to get an approximate length. However, this seems impractical for my needs because sampleTerrainMostDetailed is asynchronous.

Any recommendations?

Thank you in advance for your attention.