Using MapView.SceneToLatLng produces incorrect results

I’m trying to get the LatLng of a scene object. However, I noticed that as the map view moved, the results drifted. I found that just plugging a position into SceneToLatLng followed by LatLngToScene resulted in a completely different position.

After some trial and error, I noticed that first subtracting 2x the MapView’s position from the scene position produces the correct result. In SceneToLatLng, the MapView’s position is added to the input position, so I assume that this should instead be a subtraction. Is this a bug, or am I using it incorrectly?

Hi David,

Can I ask what your use case is? As the Map View moves it makes sense – at least from what I’m understanding – that the SceneToLatLng results would change as the Unity Vector3 input would be different. Yet, as you briefly indicated, in theory the following psuedo-code should hold true:


Vector3 a = new Vector3(1, 2, 3);
LatLng a1 = MapView.SceneToLatLng(a);

Vector3 b = MapView.LatLngToScene(a1);
LatLng b1 = MapView.SceneToLatLng(b);
Assert.IsTrue(b1 == a1);

With that being said, could you provide your code?

Kind regards,
Maverick L.

I am trying to get the current LatLng of a scene object during serialization. For this I originally tried to just use SceneToLatLng, however I noticed that trying to place an object at this coordinate resulted in the object being mirrored across the origin (eg.: as the map moved in one direction, the results from the function produced a point in the other). My function that correctly places the object looks like this:

public static LatLng GetLocation(Vector3 position) {
    return Instance.LightshipMapView.SceneToLatLng(position - 2 * Instance.LightshipMapView.transform.position);
}
public static Vector3 GetPosition(LatLng location) {
    return Instance.LightshipMapView.LatLngToScene(location);
}

The assertion you posted only passes when the map is at the origin (Vector3.zero)

Thanks for showing me your code! Could you provide me with a bit more information? What is your MapScale? Does your code continue to work properly when you change it? What is your map’s origin? Please provide the actual Vector3 coordinates in world space along with what is provided to the LightshipMapView script.

Thank you for your patience!