Topic: Smooth map moving between two geo points

Hi,

I'm trying to implement smooth moving of map after GPS data updation using your asset. Map is a tileset 2048x2048. So I have two points with latitude and longitude and I want the map moves smoothly during some time (not immidiately) from first point to second. (Player stands in the center of the map which is moving under him). I'm using Vector2.Lerp for getting intermediate points, but map moves very jumpy (not depending from step. It seems that map firstly moves in horizontal direction and after in vertical to get desired point). The zoom of tiles is 20 and average distances are about 10-100 meters as man walk. What would you suggest to do? I tried to use Vector2.Lerp with geo position and with tile coordinates after conversion but with no success. I'll be waiting for your advice.

Thank you in advance!

Re: Smooth map moving between two geo points

Hello.

I modified this example to make it as smooth as possible for zoom 20.
http://infinity-code.com/atlas/online-m … ample.html

using UnityEngine;

namespace InfinityCode.OnlineMapsExamples
{
    /// <summary>
    /// Example of a smooth movement to current GPS location.
    /// </summary>
    [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/SmoothMoveExample")]
    public class SmoothMoveExample : MonoBehaviour
    {
        /// <summary>
        /// Move duration (sec)
        /// </summary>
        public float time = 3;

        /// <summary>
        /// Relative position (0-1) between from and to
        /// </summary>
        private float angle;

        /// <summary>
        /// Movement trigger
        /// </summary>
        private bool isMovement;

        private Vector2 fromPosition;
        private Vector2 toPosition;
        private double fromTileX, fromTileY, toTileX, toTileY;
        private int moveZoom;


        private void OnGUI()
        {
            // On click button, starts movement
            if (GUI.Button(new Rect(5, 5, 100, 30), "Goto marker"))
            {
                // from current map position
                fromPosition = OnlineMaps.instance.position;

                // to GPS position;
                toPosition = OnlineMapsLocationService.instance.position;

                // calculates tile positions
                moveZoom = OnlineMaps.instance.zoom;
                OnlineMaps.instance.projection.CoordinatesToTile(fromPosition.x, fromPosition.y, moveZoom, out fromTileX, out fromTileY);
                OnlineMaps.instance.projection.CoordinatesToTile(toPosition.x, toPosition.y, moveZoom, out toTileX, out toTileY);

                // if tile offset < 4, then start smooth movement
                if (OnlineMapsUtils.Magnitude(fromTileX, fromTileY, toTileX, toTileY) < 4)
                {
                    // set relative position 0
                    angle = 0;

                    // start movement
                    isMovement = true;
                }
                else // too far
                {
                    OnlineMaps.instance.position = toPosition;
                }
            }
        }

        private void Update()
        {
            // if not movement then return
            if (!isMovement) return;

            // update relative position
            angle += Time.deltaTime / time;

            if (angle > 1)
            {
                // stop movement
                isMovement = false;
                angle = 1;
            }

            // Set new position
            double px = (toTileX - fromTileX) * angle + fromTileX;
            double py = (toTileY - fromTileY) * angle + fromTileY;
            OnlineMaps.instance.projection.TileToCoordinates(px, py, moveZoom, out px, out py);
            OnlineMaps.instance.SetPosition(px, py);
        }
    }
}
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 NightHawk91 2017-06-16 02:55:09)

Re: Smooth map moving between two geo points

Thank you very much for your reply.

But the problem of shaking map wasn't solved. I think the reason is the mechanic of map movement. This problem becomes visible only then camera is situated at the very low height over the player (3d person view) and player moves inaccurately in vertical or horizontal directions (Map plane). So I found another solution to implement the effect of player moving on the map with your marvellous asset. You made a great and very helpful asset!

Maybe I missed some documentation but I couldn't find function to get Unity position (transform.position) on the map based on the GPS coordinates as it is made in adding 3d marker on the map. Now I'm using function OnlineMapsControlBase3D.instance.AddMarker3D to get it and removes marker after but it is not very suitable to do useless activity by initiating useless markers.

And again thank you in advance.

Re: Smooth map moving between two geo points

Most likely you are looking for OnlineMapsTileSetControl.GetWorldPosition or OnlineMapsTileSetControl.GetWorldPositionWithElevation.
http://infinity-code.com/doxygen/online … 2992c6e097
http://infinity-code.com/doxygen/online … 1b7b556e6b

Kind Regards,
Infinity Code Team.

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

Re: Smooth map moving between two geo points

Yes, this is I was looking for. Thank you very much!