Latitude and longitude conversion Unity coordinates

Hello, first of all, this is a great software, but at the moment I have encountered a problem, I want to click on a point on the map by the mouse to generate an object, but an unexpected error occurred when I converted the coordinates, the converted Unity coordinate value is biased, how to solve it? Here’s my code, please help me see what’s wrong:

Vector3 objPos = camera.ScreenToWorldPoint(Input.mousePosition);
double3 vars = new double3(objPos.x, objPos.y, objPos.z);
double3 ecef = georeference.TransformUnityPositionToEarthCenteredEarthFixed(vars);
double3 lonLatHeight = CesiumWgs84Ellipsoid.EarthCenteredEarthFixedToLongitudeLatitudeHeight(ecef);

        double3 t3 = georeference.TransformEarthCenteredEarthFixedPositionToUnity(new double3(lonLatHeight.y, lonLatHeight.x, lonLatHeight.z));
        GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
        obj.AddComponent<CesiumGlobeAnchor>().positionGlobeFixed = new double3(t3.x, t3.y, t3.z);

Can you be more specific? What do you mean by “the converted Unity coordinate value is biased” ?


I followed the instructional video, set the origin, and added the CesiumOriginShift script to the camera, but the above issues still appeared. ps: This object was dynamically loaded by me

So you’re trying to place a Unity object where you click? I think you’re making that more complicated than it needs to be, as it’s no different at all from how it’s done in a normal Unity application, and need not involve Cesium at all.

Vector3 objPos = camera.ScreenToWorldPoint(Input.mousePosition);
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
obj.transform.position = objPos;

If you want it to stay fixed on the globe when the CesiumOriginShift does its thing, you also need to add a CesiumGlobeAnchor component. But there’s no need to set the globe position explicitly; it will be inferred from the Unity transform.

obj.AddComponent<CesiumGlobeAnchor>();