Topic: OnlineMaps.SetPosition not working correctly.

For some reason, OnlineMaps.SetPosition is not setting the latitude to the new value provided, while the longitude is.

In this example:

        Debug.Log("Loading at location: " + Location);
        OnlineMaps.instance.SetPosition(Location.Longitude, Location.Latitude);
        OnlineMaps.instance.zoom = zoom;
        Debug.Log("New location: " + OnlineMaps.instance.position);

I get this in the log:
- Loading at location: (Lat: 34.62605, Lng: -112.418)
- New location: (-112.3, 0.0)



This is called from the SceneManager.sceneLoaded event.

Re: OnlineMaps.SetPosition not working correctly.

Hello.

I tested this method in «SceneManager.sceneLoaded», and it works well.
Actually, this method is used in many internal methods, and if it has problem, it be appears a long time ago.
I was very confused that the problem is only in the latitude.
Try it this way:
Debug.Log ( "Loading at location: " + Location.Longitude + "   " + Location.Latitude);
Perhaps, somehow, this field is not set.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

3 (edited by nug700 2017-03-01 21:15:11)

Re: OnlineMaps.SetPosition not working correctly.

I created that LatLng (Location) struct, and the tostring method uses those fields:

return string.Format("(Lat: {0}, Lng: {1})", Latitude, Longitude);

So the field is being set.

I did try your idea: "Loading at location: -112.4193 34.62115"

I've also put a Log call inside SetPosition: "OnlineMaps.SetPosition: -112.42015838623 34.6255073547363"
To show that the values are being passed correctly.

4 (edited by nug700 2017-03-01 21:47:33)

Re: OnlineMaps.SetPosition not working correctly.

The problem seems to be coming from line 1728 (or close to) in SetPosition:

if (modified) projection.TileToCoordinates(tpx, tpy, _zoom, out lng, out lat);

before this method, lat is set to the coordinate, afterwards it is set to zero.

EDIT:
Some more information, as what's inside that function suggests it's a math issue: The zoom is set to three (before I set the zoom). The pixel size of the map is 2048x2048. The scene size of the map is 1024x1024.

EDIT:
Setting the zoom before I set the position solves the issue. Seems to be caused by the latitude being clamped to 0 at that zoom level (3).

Re: OnlineMaps.SetPosition not working correctly.

In this case, it makes sense.
Online Maps checks map boundary and corrects the latitude, if the top or bottom latitude is outside (90, -90).

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.