# Get Height of a Coordinate - Cesium for Unity

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

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

yield return null;
}
``````

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

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

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;
}