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