Where the distance actually lives in the API response
The Maps service returns a directions object with a routes array. Each route contains a legs array — one leg per waypoint segment. Each leg has a distance object whose value property is an integer in metres. A direct A-to-B trip has exactly one leg, but the reduce handles multi-leg routes without any extra logic.
Dividing by 1000 gives kilometres; dividing by 1609.344 gives miles. The function rounds to one decimal place, which is precise enough for routing work and avoids floating-point noise like 42.300000000004.
One thing that bit me early: the API returns the distance for the chosen route, not the shortest possible route. Google defaults to its recommended route (usually the fastest). If you need shortest-distance specifically, there is no direct flag — you would have to request multiple alternatives and pick the minimum, which burns extra quota calls.