Closed MephestoKhaan closed 3 years ago
Could you please provide some example lat,lons that you are experiencing issues with?
Additionally, the buildingId returned would also help.
I'd recommend trying to debug visualise the Ray here: var ray = lookingCamera.ScreenPointToRay (tapPos);
as this will help you to diagnose the issue.
I did a small project that shows the problem, here is the link: https://wetransfer.com/downloads/f1aa7553eef76421521b7e96a8b3235520171018160315/96e21375156fc2b8923c53c0dad9ecc820171018160315/f3b710
An example of the results I am getting with this code:
void HighlightAtPosition (Vector3 tapPos)
{
var ray = lookingCamera.ScreenPointToRay (tapPos);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
{
var viewportPoint = lookingCamera.WorldToViewportPoint (hit.point);
var latLongAlt = Api.Instance.CameraApi.ViewportToGeographicPoint (viewportPoint, lookingCamera);
Debug.Log(string.Format("Selecting building at: {0} {1}",latLongAlt.GetLatitude(), latLongAlt.GetLongitude()));
Api.Instance.BuildingsApi.HighlightBuildingAtLocation (latLongAlt, highlightMaterial, OnHighlightReceived);
}
}
void OnHighlightReceived (bool success, Highlight highlight)
{
Debug.Log(string.Format("Selected {0}",highlight.HighlightId));
if (success)
{
StartCoroutine (ClearHighlight (highlight));
}
}
results:
Selecting building at: 37.8024105318418 -122.405865930829
Selected landmark_us_sf_coittower
Selected landmark_us_sf_coittower01
Selected landmark_us_sf_coittower-01
Selected landmark_us_sf_coittower02
Selected landmark_us_sf_coittower-02
Selected landmark_us_sf_coittower03
Selected landmark_us_sf_coittower-03
Selected landmark_us_sf_coittower04
Selected landmark_us_sf_coittower-04
Selected landmark_us_sf_coittower05
Selected landmark_us_sf_coittower-05
Selected landmark_us_sf_coittower06
Selected landmark_us_sf_coittower-06
Selected landmark_us_sf_coittower07
Selected landmark_us_sf_coittower-07
Selected landmark_us_sf_coittower08
Selected landmark_us_sf_coittower-08
Selected landmark_us_sf_coittower09
Selected landmark_us_sf_coittower-09
Selecting building at: 37.8024094102611 -122.405871354247
Selected landmark_us_sf_coittower
Selected landmark_us_sf_coittower01
Selected landmark_us_sf_coittower-01
Selected landmark_us_sf_coittower02
Selected landmark_us_sf_coittower-02
Selected landmark_us_sf_coittower03
Selected landmark_us_sf_coittower-03
Selected landmark_us_sf_coittower04
Selected landmark_us_sf_coittower-04
Selected landmark_us_sf_coittower05
Selected landmark_us_sf_coittower-05
Selected landmark_us_sf_coittower06
Selected landmark_us_sf_coittower-06
Selected landmark_us_sf_coittower07
Selected landmark_us_sf_coittower-07
Selected landmark_us_sf_coittower08
Selected landmark_us_sf_coittower-08
Selected landmark_us_sf_coittower09
Selected landmark_us_sf_coittower-09
Quick nudge to check status here. (Luca and I are working together on this project.)
Thanks, we'll investigate this for you as a priority!
Believe what you want to use in this case is the WorldToGeographicPoint method - this lets you convert a local Unity position into a LatLongAltitude for use with the Buildings API.
void HighlightAtPosition (Vector3 tapPos)
{
var ray = lookingCamera.ScreenPointToRay (tapPos);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
{
var latLongAlt = Api.Instance.CameraApi.WorldToGeographicPoint(hit.point, lookingCamera);
Debug.Log(string.Format("Selecting building at: {0} {1}",latLongAlt.GetLatitude(), latLongAlt.GetLongitude()));
Api.Instance.BuildingsApi.HighlightBuildingAtLocation (latLongAlt, highlightMaterial, OnHighlightReceived);
}
}
However, there's a bug where the WorldToGeographicPoint
doesn't work if the root WrldMap
object is being scaled, and in your project, it's being scaled by 1/1000. We'll get this fixed for the next release, but in the meantime you can work around this by making the following changes to Wrld/Scripts/ApiImplementation.cs
:
private Transform m_parentTransform;
m_parentTransform = parentTransformForStreamedObjects;
WorldToGeographicPoint
method (line 234) modify the code to be the following:
internal LatLongAltitude WorldToGeographicPoint(Vector3 position, Camera camera)
{
if (m_coordinateSystem == CoordinateSystem.UnityWorld)
{
position = m_parentTransform.worldToLocalMatrix.MultiplyPoint(position);
return m_frame.LocalSpaceToLatLongAltitude(position);
}
else
{
var ecefPosition = m_originECEF + position;
return LatLongAltitude.FromECEF(ecefPosition);
}
}
This should transform the point into its correct space for conversion to a LatLong, and you should start seeing the correct buildings highlighting.
Thanks I will try this asap. I suspected it was something related to the scale of the map indeed.
Just as a note, I suspect the opposite (positioning elements in world space using latlong) will also be a problem if the map is scaled down. Is that something going in in the next update as well? Do you have an ETA?
You're right in that the other transforms will need similar modifications to get working too.
We're going to schedule to get the SDK properly handling scaling + transforms for a future release,
Hi! I will need a similar fix for Geographic transforms, right now they appear all far away from where they should and I imagine it is the same problem. Tried modifying GeoToWorld but did not affected it.
Making the object with the GeographicTransform component a child of the WrldApp object that is being scaled should hopefully address this - its position should then be scaled along with the rest of the world.
We'll make a note to ensure GeographicTransforms also work correctly with a scaled map as well, reguardless of where they are in the scene, for the next release.
Just checking if this has been fixed?
Likely need to add API point to nominate a Unity camera as the instance for which projection-related API points will pull camera state from.
Tracked internally as MPLY-9058.
Believe this is now fixed - please re-open if not.
I am trying the simple task of picking buildings using the sample but using arkit. And it always select the same one (the centre one), even thought the LatLong that I am getting with the code is different.
Edit: Just to add more info, I just tried with something as simple as this:
I can confirm the latLongAlt has been different every time. But the
b.BuildingId
being printed has been the same always