Topic: Real distance conversion

Hi

I want to place Marker 3D at regular interval between two locations (those are defined with  Vector2(longitude, latitude) )

Example:
nextLocation, currentLocation and direction are Vector2
Step is a float, representing the distance i want in meters

What i need to do is basically:  Vector2 nextLocation = currentLocation + direction.normalized*step;

I know that this example ( http://infinity-code.com/atlas/online-m … ample.html ) could be a part of a solution to perform this.
But somehow when i add this script to my Map GameObject it fucked up my scene. (i can't control the map anymore and all i see is a blurry tile).

Aniway i'm pretty sure it would be better to just convert my  'Step' variable from meters to game unit ?
Or, since my location point are (latitude / longitude) should i multiply "Step" with some Lat/Long constant i ignore (so finally my problem is not Unity-unit-related ?)

As you can see i'm getting confused with the best approach to achieve this yikes

Re: Real distance conversion

Hello.

Most likely you are looking for OnlineMapsUtils.GetCoordinateInDistance.
http://infinity-code.com/doxygen/online … 48f4e0636b

Kind Regards,
Infinity Code Team.

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

Re: Real distance conversion

Oh nice ! Thank you

4 (edited by Thibault 2018-10-30 18:32:25)

Re: Real distance conversion

So i'm having a hard time using this function.
See this GIF :

https://media.giphy.com/media/Bq60rkWEq … /giphy.gif

The pink line is a succession of Marker 3D that have been positioned using OnlineMapsUtils.GetCoordinateInDistance.
Those Marker 3D are supposed to be on the red line. As you can see it is working with an angle of 0 or 90 degree from the north.


Here is what i do : 
double nlng, nlat;
float angleFromNorth;
angleFromNorth = Vector2.Angle(Vector2.up, direction);

and in a loop :

OnlineMapsUtils.GetCoordinateInDistance(waypointPlacer.x, waypointPlacer.y, Step, angleFromNorth, out nlng, out nlat);

//waypointPlacer += direction * Step; //What i used to do (it is perfectly working)

waypointPlacer = new Vector2((float)nlng, (float)nlat);

waypointMarker = OnlineMapsControlBase3D.instance.AddMarker3D(waypointPlacer, waypointPrefab);


Could this be a problem caused by the fact that my lat/lng coordinates are stored in a vector2 (and so they are float instead of double, which cause precision lost ? )

So on the bright side my waypoints have now a correct distance between each other, but they doesn't follow the right direction.


PS: What does this function do exactly ?

http://infinity-code.com/doxygen/online … e6292fc96b

Re: Real distance conversion

What is the direction in your scripts?
Coordinate offset between the center point and the point that you drag?
If yes, then this is not the correct way.
You need to first convert the geographic coordinates into a tile position, and then calculate the offset.

FixAngle clamps the latitude and repeats the longitude.

Kind Regards,
Infinity Code Team.

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

Re: Real distance conversion

Vector2 direction = (pointB - pointA).normalized;

with PointA & PointB being Marker3D.position of the the center point and the one i'm dragging.

"You need to first convert the geographic coordinates into a tile position, and then calculate the offset."

A tile position ?
Do you mean that instead of using a vector2 "Marker3D.position" i should use 2 doubles, result of "Marker3D.GetTilePosition" ?

So it is a precision issue because of the conversion from double to float ?

Re: Real distance conversion

Vector2 direction = (pointB - pointA).normalized;

This is wrong, because latitude and longitude exist for a sphere or an ellipsoid.
The map is flat and in the Mercator projection.
So you need to first convert the coordinates to the Mercator projection or to the tile position, which is almost the same.

A tile position ?

Marker3D.GetTilePosition
or
OnlineMaps.instance.projection.CoordinatesToTile

So it is a precision issue because of the conversion from double to float ?

If Step is big enough, then it doesn't matter that you use a float.
If Step is small, use double.

Kind Regards,
Infinity Code Team.

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