Topic: Multiple marker followup

Hello,

I am new here on the forum and i just bought the asset.

I know how to create multiple markers. I have a question is there possible to create and focus on marker that is closer to GPS data. For example i need this map for a treasure hunt game to show the people where they need to go next.

Also how to draw a route between 17 markers on the map to show complete map.

Thank you in advance for your answer.

Best regards,

Wuchi

Re: Multiple marker followup

Hello.

How to center on the nearest marker:

using UnityEngine;

public class CenterOnNearestMarker : MonoBehaviour
{
    private void Center()
    {

        Vector2 position = OnlineMapsLocationService.instance.position;
        float bestSqrDistance = float.MaxValue;
        int bestIndex = -1;

        for (int i = 0; i < OnlineMapsMarkerManager.instance.Count; i++)
        {
            OnlineMapsMarker marker = OnlineMapsMarkerManager.instance[i];
            Vector2 markerPosition = marker.position;
            float sqrDistance = (markerPosition - position).sqrMagnitude;
            if (sqrDistance < bestSqrDistance)
            {
                bestSqrDistance = sqrDistance;
                bestIndex = i;
            }
        }

        if (bestIndex != -1)
        {
            OnlineMaps.instance.position = OnlineMapsMarkerManager.instance[bestIndex].position;
        }
    }

    private void OnGUI()
    {
        if (GUILayout.Button("Center")) Center();
    }
}

Do you mean the route or just a line?
If you mean a line, then you can do it in this way:

using System.Linq;
using UnityEngine;

public class DrawLineByMarkers : MonoBehaviour
{
    private void Start()
    {
        OnlineMapsDrawingLine line = new OnlineMapsDrawingLine(OnlineMapsMarkerManager.instance.items.Select(m => m.position).ToArray(), Color.red, 5);
        line.followRelief = true;
        OnlineMapsDrawingElementManager.AddItem(line);
    }
}

If you mean the route, then you need to make a request to some routing service (for example, Google Directions API).
Examples how to make a request and process the response is in the atlas of examples.

Kind Regards,
Infinity Code Team.

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

Re: Multiple marker followup

Thx. I will try that.