CesiumJS - Distance Between Two Points
<p>My goal is to calculate the distance between two Cesium entities in kilometers. As a bonus, I eventually want to be able to measure their distance in pixels.</p>

<p>I have a bunch of placemarks in KML format like this:</p>

<pre><code>&lt;Placemark&gt;
  &lt;name&gt;Place&lt;/name&gt;
  &lt;Point&gt;&lt;coordinates&gt;48.655,-31.175&lt;/coordinates&gt;&lt;/Point&gt;
  &lt;styleUrl&gt;#style&lt;/styleUrl&gt;
  &lt;ExtendedData&gt;
     ...
  &lt;/ExtendedData&gt;
&lt;/Placemark&gt;
</code></pre>

<p>I am importing them into Cesium like so:</p>

<pre><code>viewer.dataSources.add(Cesium.KmlDataSource.load('./data.kml', options)).then(function(dataSource) {
  var entities = dataSource.entities._entities._array;
</code></pre>

<p>I have attempted to create new Cartesian3 objects of entities I care about, but the x, y, and z values I get from the entity object are in the hundreds of thousands. The latitude and longitude from my KML are nowhere to be found in the entity objects.</p>

<p>If I do create Cartesian3 objects and compute the distance like so:</p>

<pre><code>var distance = Cesium.Cartesian3.distance(firstPoint, secondPoint);
</code></pre>

<p>it returns numbers in the millions. I have evaluated the distance between multiple points this way and when I compare those values returned to the result of an online calculator which returns the actual value in kilometers, the differences in the distances are not linear (some of the distances returned by Cesium are 900 times the actual distance and some are 700 times the actual distance).</p>

<p>I hope that is enough to receive help. I am not sure where to start fixing this. Any help would be appreciated. Thank you.</p>