Select to view content in your preferred language

Latitude and Longitude Coordinates converted to Unity World Position

1162
1
04-27-2023 12:47 PM
TBraff
by
Emerging Contributor

Hey there, I've been working with the Unity SDK for a bit, but I'm struggling in this one aspect.

Say I have a latitude and longitude, , how can I then convert those coordinates into Unity world coordinates? Ideally I'd want to do this without having to create a gameObject with an ArcGISLocationComponent.

I've seen a few functions around that seem close to what I want, but not quite. Unless I'm misunderstanding what some of these functions do, because the documentations/comments mix up terms like "geo, world, engine" that makes it confusing to figure out what exactly is being converted to what.

    public static ArcGISPoint HitToGeoPosition(Vector3 point, float yOffset = 0)
    {
        double3 worldPosition = math.inverse(map.WorldMatrix).HomogeneousTransformPoint(point.ToDouble3());
        ArcGISPoint geoPosition = map.View.WorldToGeographic(worldPosition);
        ArcGISPoint offsetPosition = new ArcGISPoint(geoPosition.X, geoPosition.Y, geoPosition.Z + yOffset, geoPosition.SpatialReference);

        return GeoUtils.ProjectToSpatialReference(offsetPosition, new ArcGISSpatialReference(4326));
    }

 

0 Kudos
1 Reply
Jade
by Esri Contributor
Esri Contributor

double3 worldPosition = arcgismap.View.GeographicToWorld(ArcGISPointPosition);

0 Kudos