Altitude on terrain not matching between Cesium.sampleTerrain and

I'm working on fetching altitude at a given position on a map which has terrain loaded into it. I found little confusing that both the below methods are returning 2 different values for near same location.

PickRay on Mousemove:

var ray =;
var position1 = viewer.scene.globe.pick(ray, viewer.scene);
if (Cesium.defined(position1)) {
   var positionCartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position1);
var height1 = positionCartographic.height.toFixed(2);


sample terrain:

Cesium.sampleTerrain(viewer.terrainProvider, 11, [cartographic])
                    .then(function () {
                        var span = document.getElementById('altData');
                        span.textContent = cartographic.height.toFixed(2);

Interestingly, I could even found that height returned from sample terrain is not right when I compare between 2 different location of a slope area.

Did I miss anything here or is this the regular behavior? How do I get altitude at given lat and long with user interaction in the screen. Anyhelp is highly appreciated.

Shiva Kumar

Hi Shiva,

The results are different because globe.pick looks at the currently rendered terrain, whereas sampleTerrain will actually retreive the values at the specified zoom level. The actually currently rendered terrain may or may not be at that same zoom level, depending on the view and which tiles are actually loaded in the scene. If you want the most accurate results (highest resolution terrain results), look into sampleTerrainMostDetailed:

Hope that helps!

  • Rachel