# The height corresponding to the latitude and longitude of the object

**URL:** <https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317>\
**Category:** Cesium for Unity\
**Created:** [July 12, 2023, 6:58am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317 "2023-07-12T06:58:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kongyu](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@kongyu](https://community.cesium.com/u/kongyu)\
**Post date:** [July 12, 2023, 6:58am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/1 "2023-07-12T06:58:31Z")

</div>

Hello, I am currently using the CESIUM globe anchor to control the latitude, longitude and height of the object, but there may be a situation where the object is floating in the air or the object is underground, is there a way to make the object stick to the surface of the earth created by CESIUM for Unity, without setting the height at any time to ensure that the object is attached to the surface of the earth, or you can obtain the height of the ground in real time to set the height of the object

---

<div class="post-metadata">

**Author:** ![kongyu](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@kongyu](https://community.cesium.com/u/kongyu)\
**Post date:** [July 12, 2023, 7:07am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/2 "2023-07-12T07:07:02Z")

</div>

For example, in the following case, if I only change the latitude and longitude of the object without changing the height, the object may appear underground, because I receive a message that only the two-dimensional latitude and longitude do not involve height, what method should I use to control the object in real time is always on the surface of the earth

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [July 12, 2023, 10:18am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/4 "2023-07-12T10:18:46Z")

</div>

There’s currently built-in way to do this. You can use a [Linecast](https://docs.unity3d.com/ScriptReference/Physics.Linecast.html) to find the height of terrain at a given 2D point. Be aware, though, that the height can change as the terrain level of detail shifts.

In the future, we plan to add a way to directly get the terrain height at a particular location. Keep an eye on this issue:

> <https://github.com/CesiumGS/cesium-native/issues/636>
>
> Similar to CesiumJS's \`sampleTerrainMostDetailed\`.

---

<div class="post-metadata">

**Author:** ![kongyu](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@kongyu](https://community.cesium.com/u/kongyu)\
**Post date:** [July 13, 2023, 1:54am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/5 "2023-07-13T01:54:01Z")

</div>

I also have a question, I was looking for Unity to use Linecast based on colliders, but Cesium World Terrain does not seem to have a unified collider, how to solve this problem

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [July 13, 2023, 9:29am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/6 "2023-07-13T09:29:55Z")

</div>

I’m afraid I don’t know what a “unified collider” is. A line cast into Cesium World Terrain should work just fine, though, as long as you haven’t disable the “Create Physics Meshes” option on the Cesium3DTileset.

---

<div class="post-metadata">

**Author:** ![kongyu](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@kongyu](https://community.cesium.com/u/kongyu)\
**Post date:** [July 14, 2023, 7:34am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/7 "2023-07-14T07:34:17Z")

</div>

At the beginning, I was unable to achieve the desired result due to the reverse direction of the line segment in Unity. Thank you very much for your help

---

<div class="post-metadata">

**Author:** ![AdamRowan](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/adamrowan/32/14000_2.png) [@AdamRowan](https://community.cesium.com/u/AdamRowan)\
**Post date:** [August 24, 2023, 1:32pm UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/8 "2023-08-24T13:32:34Z")

</div>

I’m facing a scenario where objects occasionally end up floating in the air or even sinking underground. I’m eager to find a way to ensure that my objects stay consistently aligned with the dynamic terrain surface created by CESIUM for Unity. Ideally, I’d like the objects to seamlessly stick to the terrain without manually adjusting their height all the time. Is there [a](https://pinterestvideodownloader.io/) technique or approach within CESIUM that allows objects to naturally conform to the terrain’s surface?

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [August 25, 2023, 2:54am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/9 "2023-08-25T02:54:52Z")

</div>

No, there’s currently no easy out of the box way to do that. We recognize the need, though, and would like to provide one in the future. In the meantime, line casts are the best available option.

---

<div class="post-metadata">

**Author:** ![Fernando\_Bertezzolo](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/fernando_bertezzolo/32/15280_2.png) [@Fernando\_Bertezzolo](https://community.cesium.com/u/Fernando_Bertezzolo)\
**Post date:** [August 30, 2023, 12:58pm UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/10 "2023-08-30T12:58:38Z")

</div>

I’ve tried this but there are some places where the raycast is not hiting.  
Is the mesh also set for the sea?

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [August 31, 2023, 12:20am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/11 "2023-08-31T00:20:50Z")

</div>

Yes, there’s a mesh for the sea as well. However, tiles that are not currently visible are not shown by default, and so it’s not possible for a raycast to hit them. See here, especially the part about “Tile culling and LODs”:

> **[Placing Objects on the Globe](https://cesium.com/learn/unity/unity-placing-objects/#notes)**
>
> This tutorial demonstrates how Cesium for Unity integrates with Unity and explains how to add simple Unity objects to a level.

---

<div class="post-metadata">

**Author:** ![liuwenkai](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/liuwenkai/32/14000_2.png) [@liuwenkai](https://community.cesium.com/u/liuwenkai)\
**Post date:** [October 12, 2023, 2:26am UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/12 "2023-10-12T02:26:35Z")

</div>

Hello, has this function been updated?

---

<div class="post-metadata">

**Author:** ![janine](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/janine/32/5135_2.png) [@janine](https://community.cesium.com/u/janine)\
**Post date:** [October 2, 2024, 7:18pm UTC](https://community.cesium.com/t/the-height-corresponding-to-the-latitude-and-longitude-of-the-object/25317/13 "2024-10-02T19:18:33Z")

</div>

Hey everyone! Just wanted to update that as of Cesium for Unity v1.13.0, you can now use the asynchronous `SampleHeightMostDetailed` function to query the height on a tileset, at a given longitude / latitude position. Remember that this height is returned in **meters above the WGS84 ellipsoid**!

You can find a quick example in the comment on this PR: [Height query API for Unity by kring · Pull Request #507 · CesiumGS/cesium-unity · GitHub](https://github.com/CesiumGS/cesium-unity/pull/507#issuecomment-2380048726)
