# How do I find the height information given x and z of the Cesium Map

Hi, I want to spawn prefabs using a C# scripts at a specific location on the map. I have the x and z World coordinate but I need to figure out the height (World y coordinate). I tried using Raycasting to no avail. Is there a built-in Cesium function (Return Height) for this?

Thanks

Call it via a web component using a web service that will echo back the altitude for that location.

Could you provide the exact reference of the function of the Cesium API?

Thanks.

https://cesium.com/learn/cesiumjs/ref-doc/HeightReference.html

I donâ€™t think you can get this value inside Cesium for Unity. You will therefore have to call it via a third party (https://www.geonames.org/) webservice and then use that value for your spawned objectsâ€™ altitude. However, you will have to calibrate an offset in relation to the actual surface.

Raycasting is the only built-in option currently. If you elaborate on â€śno availâ€ť thereâ€™s a chance we might be able to help.

Calling an external web service could be a good option, too, though I canâ€™t help you with the specifics on that.

What I tried was to shoot a ray vertically (I tried both directions: up and down) and tried to find the intersection point with the Cesium map. Assume x_center and z_center to be 0 and 0 in the world space. Assume that the Cesium map is somewhere around y= - 2000

``````    float x_random = Random.Range(x_center-cell_size/2, x_center+cell_size/2);
float z_random = Random.Range(z_center-cell_size/2, z_center+cell_size/2);
Vector3 origin = new Vector3(x_random, -1000000f, z_random); // Start the raycast from a high point
Vector3 direction = Vector3.up;
Ray ray = new Ray(origin, direction);
RaycastHit hit;

if (Physics.Raycast(ray, out hit, 10000000000000))
{
return hit.point.y;
}
``````

This doesnâ€™t yield any intersection.

Hi @beepboop,

Just to be sure, can you confirm that you have â€śCreate Physics Meshesâ€ť enabled on the tileset?

If that is enabled, and this still isnâ€™t working, can you share when exactly youâ€™re casting the ray? 3D Tiles will take a few frames to stream in, so raycasting at the beginning of the application is essentially raycasting into empty space. The tiles need to load into the scene before you can raycast against them.

I had success getting height of a specific position on the tiles if i wait for several seconds until the tiles have successfully been instantiated.
But ideally there would be a callback/event system in place that triggers after a tile has successfully landed in the scene and is ready to be used/queried/raycast against. But there doesnt seem to be anything li!e that implemented in the unity plugins
This seems like a gap and oversight. Is something like that in the backlog/planned? Or is extending such things on a custom unity plugin fork the only option?

You can subscribe to be notified when each tile is loaded:

1 Like

Awesome, thanks !
â†’ didâ€™nt find anything like that back when i searched for it , so i guess those are rather new ?

Introduced in v1.4.0 (early July) and v1.6.0 (early September), respectively.

Hi, I was implemented OnTileGameObjectCreated as well as ComputeLoadProgress() which both work great for Cesium tiles, however I dont get anything when streaming in Google Photo 3D Tileset however. Does that sound right, that it wouldnt work for that source?

I noticed in another post about enabling LogSelectionStats and that seems like it would do the trick, I was just hoping the first two options might work.