Convert From Cartesian3 to Longitude and Latitude with High Precision onTerrain

Hello!

I need to make a new entity from a longitude and latitude with terrain. Going from a cartesian3 to a longitude and latitude involves a loss of precision. But I want a longitude and latitude, and I want them to be precise! Is this possible via the Cesium API?

For each sandcastle provided, first maneuver the camera over some terrain. The Rocky Mountains is a good place. Next, zoom in to very low altitudes. Then, maneuver the camera and tilt the globe so that your camera is sitting on the side of a mountain, and you are looking over a range of terrain heights. Finally, click around on the various terrain heights at different places in the viewport. Note how in the lonlat sandcastle, the marker is placed near-ish to your click spot. This problem is accentuated close to the bottom of the viewport. In the cartesian3 sandcastle, the marker placement is spot on.

What I want to do but isn’t working is in the lonlat sandcastle below:

A workaround is in the cartesian3 sandcastle below:

I really want to use latitude and longitude to create a new entity. While the workaround posted above is fine for this trivial example, in my case, using a latitude or longitude, maintaining original precision, is highly desirable. Is this possible via the Cesium API?

I am on Cesium 1.26. This happens in IE, Chrome, FF, and Vivaldi.

Thanks in advance!

I posted the wrong sandcastle. Here is the lonlat sandcastle:

http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=2c8a4dafae2f0fdf706c086210649dd7

For the lon/lat example, you are placing the billboard on the surface of the ellipsoid. Since terrain is enabled, you need to take the height into account. Everything looked fine to me after changing the entity position to:

Cesium.Cartesian3.fromDegrees(lon, lat, cartographic.height)

Dan

Dan, thanks for the response! Thrilled to see it.

Unfortunately, for my use case, since height is a property given by the click event payload that is not latitude or longitude, I cant use it in the constructor.

One potential workaround that doesnt quite seem to be working is setting the height reference to CLAMP_TO_GROUND. Ideally, thats the way I would achieve this. To my understanding, that should place the marker on the globe sitting directly on top of the terrain. Why do we need to pass the height in when theres CLAMP_TO_GROUND?