Hello.
I just checked it. Waypoints are used. Test the code below.
In Online Maps v2.4 we have added the ability to pass parameters using the object.
I think this way is much more readable, extensible, and solves the problem of who is first (latitude and longitude), because you can use object[], where each item Vector2 or string.
The order of variables is opposite of what your api dictates. Google takes LatLng not LngLat.
Long time ago (in the first versions of Online Maps v1.x), we used the geographical way (latitude first).
This caused a ton of problems for users because it conflict with another rule: X first. X - is a longitude.
So now in Online Maps API everywhere X (or lng) first.
8 waypoint limit is good to know btw
It is not described in Google Directions API documentation, and I do not know about it.
We will add it in description of the method / variable.
I have a few weird bugs which i think are related to race conditions. Is there a certain flow of events i should implement before using the map to make sure it's all loaded?
Unfortunately, I did not understand your question.
Please rephrase it.
Test of FindDirectionAdvanced with waypoint (Online Maps v2.4 way):
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class TestFindDirectionWithWaypoints:MonoBehaviour
{
private void OnFindDirectionComplete(string response)
{
OnlineMapsFindDirectionResult result = OnlineMapsFindDirectionAdvanced.GetResult(response);
if (result != null)
{
Debug.Log(result.routes.Length);
foreach (OnlineMapsFindDirectionResult.Route route in result.routes)
{
OnlineMaps.instance.AddDrawingElement(
new OnlineMapsDrawingLine(route.overview_polyline.ToList(), Color.red, 3)
);
}
}
else
{
Debug.Log(response);
}
}
private void OnGUI()
{
if (GUILayout.Button("Test"))
{
OnlineMapsMarker[] markers = OnlineMaps.instance.markers;
if (markers.Length < 3) return;
Vector2 origin = markers[0].position;
Vector2 destination = markers[markers.Length - 1].position;
List<Vector2> waypoints = new List<Vector2>();
for (int i = 1; i < markers.Length - 1; i++) waypoints.Add(markers[i].position);
OnlineMapsFindDirectionAdvanced.Find(
new OnlineMapsFindDirectionAdvanced.Params(origin, destination)
{
waypoints = waypoints.Cast<object>().ToArray(),
alternatives = true,
mode = OnlineMapsFindDirectionMode.bicycling
}
).OnComplete += OnFindDirectionComplete;
OnlineMaps.instance.RemoveAllDrawingElements();
}
}
private void OnMapClick()
{
Vector2 coords = OnlineMapsControlBase.instance.GetCoords();
OnlineMaps.instance.AddMarker(coords, "Marker" + (OnlineMaps.instance.markers.Length + 1));
}
private void Start()
{
OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
}
}
Kind Regards,
Infinity Code Team.
Boost your productivity a lot and immediately using
Ultimate Editor Enhancer.
Trial and non-commerce versions available.