# Get Height of a Coordinate - Cesium for Unity

**URL:** <https://community.cesium.com/t/get-height-of-a-coordinate-cesium-for-unity/23990>\
**Category:** Cesium for Unity\
**Created:** [May 12, 2023, 5:22pm UTC](https://community.cesium.com/t/get-height-of-a-coordinate-cesium-for-unity/23990 "2023-05-12T17:22:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crunchrock](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/crunchrock/32/13635_2.png) [@crunchrock](https://community.cesium.com/u/crunchrock)\
**Post date:** [May 12, 2023, 5:22pm UTC](https://community.cesium.com/t/get-height-of-a-coordinate-cesium-for-unity/23990/1 "2023-05-12T17:22:11Z")

</div>

Hello, I’m trying to use a location loader to go through location data that includes long and lat. I need to be able to place pins at places on the map and set the camera height for specific locations and glide between them. I’m pretty lost trying to use cesiumgeoreference from my locationmanager to convertGeodetic to ecef and then into a unity format, i put fictional methods called geodectictoecef and eceftounity in my code below but i need to know what to call from getterrainheightat to get the real height i can use to calculate pin and camera height.

private double GetTerrainHeightAt(double longitude, double latitude)  
{  
// Convert geodetic coordinates to ECEF, then to Unity world coordinates  
Vector3d ecefPos = GeodeticToEcef(longitude, latitude, 0);  
Vector3 unityPos = EcefToUnity(ecefPos);

```
    // Use a raycast to find the terrain height
    RaycastHit hit;
    if (Physics.Raycast(unityPos + Vector3.up * 10000f, Vector3.down, out hit, 20000f))
    {
        // We hit something, return the y coordinate of the hit point
        return hit.point.y;
    }
    else
    {
        // Raycast did not hit any terrain
        Debug.LogError("Raycast did not hit any terrain");
        return 0.0;
    }
}

private IEnumerator CreatePin(Location location)
{
    double latitude = double.Parse(location.latitude);
    double longitude = double.Parse(location.longitude);
    double height = GetTerrainHeightAt(longitude, latitude);

    // Create a new pin
    GameObject pin = Instantiate(pinPrefab, pinParent);

    // Add a CesiumGlobeAnchor component to the pin
    CesiumGlobeAnchor anchor = pin.AddComponent<CesiumGlobeAnchor>();

    // Set the anchor's longitude, latitude, and height
    anchor.longitudeLatitudeHeight = new double3(longitude, latitude, height + pinHeightOffset);

    yield return null;
}

```

---

<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:** [May 12, 2023, 6:07pm UTC](https://community.cesium.com/t/get-height-of-a-coordinate-cesium-for-unity/23990/2 "2023-05-12T18:07:46Z")

</div>

Can you be more specific with what you’re trying to achieve? “Height” is ambiguous here, do you mean height above sea level?

---

<div class="post-metadata">

**Author:** ![crunchrock](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/crunchrock/32/13635_2.png) [@crunchrock](https://community.cesium.com/u/crunchrock)\
**Post date:** [May 12, 2023, 6:37pm UTC](https://community.cesium.com/t/get-height-of-a-coordinate-cesium-for-unity/23990/3 "2023-05-12T18:37:12Z")

</div>

Thanks for replying, im referring to height above terrain asset. i want 3d pins and the camera to be set above this.

---

<div class="post-metadata">

**Author:** ![crunchrock](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/crunchrock/32/13635_2.png) [@crunchrock](https://community.cesium.com/u/crunchrock)\
**Post date:** [May 12, 2023, 6:39pm UTC](https://community.cesium.com/t/get-height-of-a-coordinate-cesium-for-unity/23990/4 "2023-05-12T18:39:26Z")

</div>

I came up with this to solve that specific issue. I think it might be working but my camera is continue to rotate and move after i switch my location coordinates

private double3 GeodeticToEcef(double longitude, double latitude, double height)  
{  
return CesiumWgs84Ellipsoid.LongitudeLatitudeHeightToEarthCenteredEarthFixed(new double3(longitude, latitude, height));  
}

private Vector3 EcefToUnity(double3 ecefPos)  
{  
// Convert ECEF to Unity world coordinates  
double4 ecefPos4 = new double4(ecefPos.x, ecefPos.y, ecefPos.z, 1.0);  
double4 unityPos4 = math.mul(cesiumGeoreference.ecefToLocalMatrix, ecefPos4);  
Vector3 unityPos = new Vector3((float)unityPos4.x, (float)unityPos4.y, (float)unityPos4.z);  
return unityPos;  
}
