Select to view content in your preferred language

Doubt to access latitude and longitude

537
2
12-27-2023 09:17 PM
Manoj081498
Emerging Contributor

Hi Everyone 

I am new to unity I have a doubt

ArcGIS Location is the location of camera. Is there any way to get the location of cursor where we point mouse pointer in the map

0 Kudos
2 Replies
ChrisRenzi
Emerging Contributor

Since you are new to Unity, I would check out the Camera.ScreenToWorldPoint (https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html) method to learn more about how Unity translates the x/y screen point(2D) into a world point(3D).
Once you understand that, you can get the lat/long location of the map as follows:
In a script that is attached to the Map GameObject, you will need to cast a ray from the camera at the touch position.  touchPos is a Vector3 point where the screen is touched
Ray ray = Camera.main.ScreenPointToRay(touchPos);
RaycastHit[] hits = UnityEngine.Physics.RaycastAll(ray);

In the hits array, one of the hits will be a hit on the map.  Using the point property of the hit you can get the lat/lng as follows:
ArcGISMapComponent mapComponent = gameObject.GetComponentInParent<ArcGISMapComponent>();
ArcGISPoint coords = mapComponent.EngineToGeographic(h.point);

lat = coords.Y;
lng = coords.X;


Review the ArcGISPoint API reference here:
https://developers.arcgis.com/unity/api-reference/gameengine/geometry/arcgispoint/

0 Kudos
Manoj081498
Emerging Contributor

I have tried what you said but it is not working.

can you assist further

 

0 Kudos