How to get coordinates (longitude, latitude, altitude) on mouse click (can't get altitude)

Hi all!
I am trying to get coordinates on mouse click. My code:

//get position from globe and set model
function getPositionFromGlobe() {
var viewer = Earth.variables.cesiumViewer;
var scene = Earth.variables.cesiumScene;

var ellipsoid = scene.globe.ellipsoid;

var cartographic;
var longitudeString;
var latitudeString;
var heightString;

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas),
    onEarthClick = function (e) {
        if (e.which == 3) {//right button
            $(this).unbind('mousedown', onEarthClick);

            Earth.variables.currentModel.longitude = parseFloat(longitudeString);
            Earth.variables.currentModel.latitude = parseFloat(latitudeString);
            Earth.variables.currentModel.altitude = parseFloat(heightString);


handler.setInputAction(function (movement) {
    var cartesian =, ellipsoid);
    if (cartesian) {
        cartographic = ellipsoid.cartesianToCartographic(cartesian);
        longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(15);
        latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(15);
        heightString = Cesium.Math.toDegrees(cartographic.height).toFixed(15);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);



If I use with standart terrain - I can get longitude and latitude, but altitude is always = 5 or 10.
When I use smallterrain ( or STK World terrain meshes, I get altitude = 5 or 10 too.
It`s important for me to get altitude from clicked point. I can not put model correctly on the hills or mountains.
Anyone can tell me the way to do this?


You can use camera.getPickRay to get the height:

var ray =;

var position = viewer.scene.globe.pick(ray, viewer.scene);

if (Cesium.defined(position)) {

var cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
var height = cartographic.height


You don’t have to use Cesium.Math.toDegrees on the height, it is given in meters.

You can also use the ScreenSpaceEventHandler to handle the click event directly.

Use ScreenSpaceEventType.LEFT_CLICK. Then, replace movement.endPosition with movement.position in the handler function.