Select to view content in your preferred language

How can i get lat/lon position of the player (Main Camera)

1082
3
06-13-2023 04:51 AM
WH1981
by
Regular Contributor

Hello,

I'm trying to get the coordinates (Lat/ lon) of the player (main camera) with a button. But when i move in the game and hit the button  the coordinates stays the same as the beginning.

		GisLocation = Camera.main.GetComponent<ArcGISLocationComponent>();
		//Afstand.text = "X: " + GisLocation.Position.X.ToString() + " Y: " + GisLocation.Position.Y.ToString() + " Z: " + GisLocation.Position.Z.ToString();
		Debug.Log(GisLocation.Position.Y);

How can i access the coordinates.

 

 

0 Kudos
3 Replies
ZackAllen
Esri Contributor

HI WH1981. For getting coordinates from a position, I suggest using the `WorldToGeographic` method from `ArcGISView`. 

ArcGISPoint geoPosition = mapComponent.View.WorldToGeographic(worldPosition);


I hope this helps,
Zack

0 Kudos
WH1981
by
Regular Contributor

Hello Zack, I now have this, but i need the worldPosition. How do i get that?

 

 

ArcGISPoint geoPosition = arcGISMapComponent.View.WorldToGeographic(worldPosition);

 

 

I find also this and worldpos is worldposition.

 

double3 worldPos = map.View.GeographicToWorld(new ArcGISPoint(x, y, spatialRef));
map = the ArcGISMapComponent; spatialRef = new ArcGISSpatialReference(4326); x,y = 5.1 & 52.1 (example)

 

But the x and y is filled in here. How do i get the Unity x and y of the camera position?

0 Kudos
WH1981
by
Regular Contributor

Update: found a solution. I place a empty object under the XR RIG. And add the ArcGIS Location component to it.

 

		CoorXY = GameObject.FindWithTag("XY");
		var GisLocation = CoorXY.GetComponent<ArcGISLocationComponent>();
		text.text = GisLocation.Position.X.ToString() + GisLocationMain.Position.Y.ToString();

 

0 Kudos