Retrieving the Lat/Lon/Elevation from a raycast click

Hi, I’m trying to retrieve a lat/lon and height of where I have clicked on the generated map in Cesium.

Typically, I’d use physics ray cast to fire a ray to hit something, but this is just going to hit a unity world-space position. I need to know the Lat/Lon/elevation of where I clicked on the terrain.
Bing maps had something similar where I could click on the map and it would return the lat/lon/elevation of where I clicked.

Is this possible as I use it to calculate distances between a point a user has clicked and another point?


Yep. Do your raycast. Then feed the Unity position into the TransformUnityPositionToEarthCenteredEarthFixed method on the CesiumGeoreference component, to get an ECEF position:

Then pass that to the static EarthCenteredEarthFixedToLongitudeLatitudeHeight method on CesiumWgs84Ellipsoid to get the longitude/latitude/height (in that order!):

1 Like

Note that the height is above the WGS84 ellipsoid, not to be confused with an elevation above sea level.

is there a conversion in cesium for Unity to convert that to an elevation above sea level or would we need to calculate that ourselves? If ourselves, do you have a suggestion?
thank you

There is currently nothing built-in. Keep an eye on this issue:

I haven’t tried it, but something like this would probably do the job: