Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform extension method MoveToGeocoordinate() doesn't work correctly? #60

Closed
binakot opened this issue May 9, 2017 · 7 comments
Closed

Comments

@binakot
Copy link

binakot commented May 9, 2017

It's me again 😈 . Now I can't place objects on the map by their geo coordinates. In earlier version of SDK it worked like a charm, but now it confused me. I'm using version 0.5.1-beta.

For test I created this script:

public sealed class PlaceAtLatLng : MonoBehaviour
{
    public double Latitude;
    public double Longitude;

    private void Update()
    {
        transform.MoveToGeocoordinate(Latitude, Longitude, Vector2d.zero);            
    }
}

For example, I set latitude = 55.7481 and longitude = 37.6196. And same values I use in MapController. By idea the object should appear in the center of the generated map. But when I press play button in Unity editor, the object has really wrong position values, smth like (4187795, 0, 7508432).

map-controller

test-object

What do I wrong?

@brnkhy
Copy link
Contributor

brnkhy commented May 9, 2017

Hey @binakot!
It actually works but the problem is, it puts the object relative to the origin of the mercator projection system. So that lat/lng is most likely around those value (in meters) but the problem is, your world, or let's say your current tiles, are not.
Mesh generation stuff builds everything in relative position to prevent those huge numbers, so what you have to do there is to pass the position of you central tile instead of Vector2.zero in that call. I believe MapController class has the central tile reference in the current version so it should work if you simply use ReferenceTileRect.Center there.

@david-rhodes
Copy link

@binakot MoveToGeocoordinate has been decoupled from MapController. Now, the method accepts additional arguments, such as refPoint and scale. For accurate placement, you need to pass these parameters in.

Try this:

	private void Update()
	{
            transform.MoveToGeocoordinate(Latitude, Longitude, MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor);
	}

@brnkhy Can you shed some light on your future improvements with regards to removing these static references, please?

@binakot
Copy link
Author

binakot commented May 9, 2017

@brnkhy @david-rhodes Yes, it works when I pass MapController.ReferenceTileRect.Center and MapController.WorldScaleFactor in my test script. But I got NPE when I initialize objects of my data model on app running. It's not good idea to store it in static values.

binakot added a commit to binakot/Fleet-And-Staff-Location-Visualizer that referenced this issue May 9, 2017
Now, the method accepts additional arguments, such as refPoint and
scale.
mapbox/mapbox-unity-sdk#60
@brnkhy
Copy link
Contributor

brnkhy commented May 9, 2017

@binakot static references will be removed soon and but still, you'll have to get the reference point from MapVisualization. In your case, you're simply doing your thing before the world is initialized and some critical properties are calculated/defined.
What we'll do though, is to create an event inside MapVisualization and then you'll be able to trigger your stuff to that event easily. Actually you can do that with the MapController class at the moment as well, just add an event and fire it right after ReferenceTile is set etc. That would solve your issue for now.

binakot added a commit to binakot/Fleet-And-Staff-Location-Visualizer that referenced this issue May 9, 2017
Add stupid hotfix with the coroutine. Waiting for MapController
ReferenceTileRect value initialization to avoid NPE.
mapbox/mapbox-unity-sdk#60
@binakot
Copy link
Author

binakot commented May 9, 2017

@brnkhy Okay, thanks. Atm I just added stupid coroutine with while loop until MapController will not initialized. And it works. I will add an event logic later probably, or just will wait next SDK release 🍸 Cheers!

@Spaxe
Copy link
Contributor

Spaxe commented May 10, 2017

Thanks for this timely issue, @binakot. I ran into the exact same problem when upgrading from SDK 0.4.0 to 0.5.1.

Edit: I did a similar hack with TerrainFactory mesh generation complete, because I need to do expensive one-time raycasting to match terrain height, but only when it's loaded.

@david-rhodes
Copy link

Improved: #62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants