Direct instruments like a scale or caliper cannot reach the height of a tree, let alone the distance to the Moon or a planet -- these need indirect geometric or wave-based methods.
Triangulation method (for the height of an accessible object): stand at point C, a known horizontal distance x from the base B of a tower/tree of height h=AB, and measure the angle of elevation θ=∠ACB to the top A with a range finder. From the right triangle ABC: tanθ=h/x, so
h=xtanθ.
Parallax method (for the distance of a far-away object like a planet or star): parallax is the apparent shift in an object's position against a distant background when it is viewed from two different points; the separation between those points is the basis, b. If the small parallax angle subtended at the object is θ, and x is the (large) unknown distance, treating the basis as a small arc of a circle of radius x gives θ=b/x, so
x=θb(θ in radians).
Application -- distance of the Moon: observe the Moon simultaneously from two diametrically opposite points A,B on Earth (basis b=AB= Earth's diameter), each against the same distant background star; the individual parallax angles θ1,θ2 add to give the Moon's total parallax θ=θ1+θ2. Since the Earth-Moon distance MC≈AM, θ≈AB/MC, so MC=AB/θ.
RADAR method (RAdio Detection And Ranging): beam a radio pulse toward a nearby planet and time the round-trip interval t until its echo returns. Since the pulse covers the distance twice (out and back) at the wave speed v (= speed of light):
d=2vt.
The same round-trip-timing idea (with the speed of sound instead of light) underlies sonar ranging underwater, and RADAR/sonar-style timing can equally determine the altitude of an aircraft.
Practical distance units that make astronomical numbers manageable: 1 light year =9.467×1015 m (distance light travels in vacuum in one year); 1 astronomical unit (AU, mean Earth-Sun distance) =1.496×1011 m; 1 parsec (distance at which a 1 AU arc subtends a parallax angle of exactly 1 arc-second) =3.08×1016 m =3.26 light years. Quoting a star's distance in light years or parsecs, rather than kilometres, avoids writing out an unwieldy number of digits every time.