Hello,
I am trying to get the Unity position from geographical coordinates, I have the following code to get the HPTransform position, but I am not sure how to continue from here, (I'm not sure if this is even possible),
double3 worldPos = map.View.GeographicToWorld(new ArcGISPoint(x, y, spatialRef));
map = the ArcGISMapComponent; spatialRef = new ArcGISSpatialReference(4326); x,y = 5.1 & 52.1 (example)
This results in: worldPos = double3(568832.151913682, 0, 6816306.77166522)
I have looked a bit in to the HPTransform code, but I couldn't figure out how it worked.
Some more details about the project: I do not use the rebase component on the ArcGISCamera & and the ArcGISCamera is on a fixed location, and I'm using a local scene.
Thanks for the help,
Kind regards,
Reint.
Solved! Go to Solution.
Hello again,
After some more testing and diving in to the code, I think I got it to work,
I used the following code to transform the worldPos variable to the Unity position, using the HPRoot of the ArcGISMap component:
HPRoot root = map.GetComponent<HPRoot>();
double3 unityPos = root.TransformPoint(worldPos))
I'm not sure if this is a valid method that also works in global scenes for example, but it seems to work for local scenes.
Is this value This results in: worldPos = double3(568832.151913682, 0, 6816306.77166522) not correct?
I need the transform.position for a raycast, and the worldPos is the value of the HPTrarnsform.UniversePosition.
Hello again,
After some more testing and diving in to the code, I think I got it to work,
I used the following code to transform the worldPos variable to the Unity position, using the HPRoot of the ArcGISMap component:
HPRoot root = map.GetComponent<HPRoot>();
double3 unityPos = root.TransformPoint(worldPos))
I'm not sure if this is a valid method that also works in global scenes for example, but it seems to work for local scenes.
Ok, any reason you aren't just using a location component on the object of interest?
Hey Matt, I wanted to create a moderate/large amount of objects after the game has started. I think the code is a bit cleaner and more optimized if you can get the height beforehand (so the object it self does not need a seperate script/function to get the height) (and you need to wait a frame before the transform.position is updated, if I'm corrent).
However, this only works because my project area is kind of small, so everything location is loaded, it would not work with larger areas.
Ok sounds good. So the solution you shared should work.
Hello,
I have tried your solution, but my ArcGISView does not have a SpatialReference. Do you know how I can assign one?
Thank you for posting this! Thanks to this info, I was able, not only to get a Unity-world location for a geographic coordinate, but also to use HPRoot.InverseTransformPoint() to go the other direction and get a WGS coordinate for a Unity object without a location component.
Sorry, but where is the variable "map" comes from? Do I need to use FindObjectByTags or something else?