<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Correct waypoint format]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=204</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=204&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Correct waypoint format.]]></description>
		<lastBuildDate>Tue, 26 Jul 2016 11:02:50 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Correct waypoint format]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=937#p937</link>
			<description><![CDATA[<p>Hello.</p><p>I just checked it. Waypoints are used. Test the code below.<br />In Online Maps v2.4 we have added the ability to pass parameters using the object.<br />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.</p><div class="quotebox"><blockquote><p>The order of variables is opposite of what your api dictates. Google takes LatLng not LngLat.</p></blockquote></div><p>Long time ago (in the first versions of Online Maps v1.x), we used the geographical way (latitude first). <br />This caused a ton of problems for users because it conflict with another rule: X first. X - is a longitude.<br />So now in Online Maps API everywhere X (or lng) first.</p><div class="quotebox"><blockquote><p>8 waypoint limit is good to know btw</p></blockquote></div><p>It is not described in Google Directions API documentation, and I do not know about it. <br />We will add it in description of the method / variable.</p><div class="quotebox"><blockquote><p>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&#039;s all loaded?</p></blockquote></div><p>Unfortunately, I did not understand your question.<br />Please rephrase it.</p><p>Test of FindDirectionAdvanced with waypoint (Online Maps v2.4 way):<br /></p><div class="codebox"><pre><code>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(&quot;Test&quot;))
        {
            OnlineMapsMarker[] markers = OnlineMaps.instance.markers;
            if (markers.Length &lt; 3) return;

            Vector2 origin = markers[0].position;
            Vector2 destination = markers[markers.Length - 1].position;

            List&lt;Vector2&gt; waypoints = new List&lt;Vector2&gt;();

            for (int i = 1; i &lt; markers.Length - 1; i++) waypoints.Add(markers[i].position);

            OnlineMapsFindDirectionAdvanced.Find(
                new OnlineMapsFindDirectionAdvanced.Params(origin, destination)
                {
                    waypoints = waypoints.Cast&lt;object&gt;().ToArray(),
                    alternatives = true,
                    mode = OnlineMapsFindDirectionMode.bicycling
                }
                ).OnComplete += OnFindDirectionComplete;

            OnlineMaps.instance.RemoveAllDrawingElements();
        }
    }

    private void OnMapClick()
    {
        Vector2 coords = OnlineMapsControlBase.instance.GetCoords();
        OnlineMaps.instance.AddMarker(coords, &quot;Marker&quot; + (OnlineMaps.instance.markers.Length + 1));
    }

    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 26 Jul 2016 11:02:50 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=937#p937</guid>
		</item>
		<item>
			<title><![CDATA[Re: Correct waypoint format]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=932#p932</link>
			<description><![CDATA[<p>have since revised the code a little.</p><div class="codebox"><pre><code>void OnGUI(){
        if(GUILayout.Button(&quot;GENERATE&quot;)){
            List&lt;OnlineMapsMarker&gt; selectedRoute = categorisedMarkers[GPSCategory.POPULAR];
            string[] wayPoints = new string[selectedRoute.Count];
            for(int i = 0; i &lt; selectedRoute.Count; i++){
                double lat, lng;
                OnlineMaps.instance.GetPosition(out lng, out lat );
                wayPoints[i] = lat +&quot;,&quot;+ lng;
            }
            OnlineMapsGoogleAPIQuery query = OnlineMapsFindDirectionAdvanced.Find( selectedRoute[0].position, selectedRoute[selectedRoute.Count-1].position, OnlineMapsFindDirectionMode.bicycling, wayPoints);
            query.OnComplete += OnFindDirectionComplete;
        }
    }</code></pre></div><p>Seems to get paths now (8 waypoint limit is good to know btw). The order of variables is opposite of what your api dictates. Google takes LatLng not LngLat. So i switched them around in a &#039;,&#039; string it and seems to work though it completely ignores the waypoints and simply goes from start to end. Even with optimize=true ripped out of the url.</p><p>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&#039;s all loaded?</p>]]></description>
			<author><![CDATA[null@example.com (SuperBuf)]]></author>
			<pubDate>Tue, 26 Jul 2016 08:28:36 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=932#p932</guid>
		</item>
		<item>
			<title><![CDATA[Re: Correct waypoint format]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=931#p931</link>
			<description><![CDATA[<p>Hi,</p><p>Yeah sorry, should clarify. It&#039;s a list of OnlineMapsMarkers. OnlineMapsFindDirectionAdvanced requires a string[] to be sent across. I imagine this is a lat,long string. Hence the position. What else should i send a long? I want to plot a path between markers.</p>]]></description>
			<author><![CDATA[null@example.com (SuperBuf)]]></author>
			<pubDate>Tue, 26 Jul 2016 07:48:32 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=931#p931</guid>
		</item>
		<item>
			<title><![CDATA[Re: Correct waypoint format]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=919#p919</link>
			<description><![CDATA[<p>Hello.</p><p>What is «selectedRoute» and «selectedRoute.position»?<br />selectedRoute - is some List, right?<br />List of what? OnlineMapsFindDirectionResult does not contain «position».</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Mon, 25 Jul 2016 18:04:41 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=919#p919</guid>
		</item>
		<item>
			<title><![CDATA[Re: Correct waypoint format]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=918#p918</link>
			<description><![CDATA[<p>Okay, weird behaviour and no clue why, but disabling the debug.log results in a failed path. Reenabling it makes it work..</p><div class="codebox"><pre><code>for(int i = 0; i &lt; selectedRoute.Count; i++){
            Debug.Log(selectedRoute[i].position.x +&quot; &quot;+ selectedRoute[i].position.y );
            wayPoints[i] = selectedRoute[i].position.y +&quot;,&quot;+ selectedRoute[i].position.x;
        }</code></pre></div><p>It seems position is not initialised until the first call??</p>]]></description>
			<author><![CDATA[null@example.com (SuperBuf)]]></author>
			<pubDate>Mon, 25 Jul 2016 17:27:44 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=918#p918</guid>
		</item>
		<item>
			<title><![CDATA[Correct waypoint format]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=916#p916</link>
			<description><![CDATA[<p>What&#039;s the proper string format for waypoints in Advanced Direction search?</p><p>Example url that i&#039;m sending out that is failing: <br /></p><div class="codebox"><pre><code>https://maps.google.com/maps/api/directions/xml?origin=50.89974,5.749269&amp;destination=50.82225,5.771378&amp;sensor=false&amp;waypoints=optimize:true|50.89974,5.749269|50.86686,5.773848|50.8013,5.699512|50.79523,5.685507|50.78641,5.724956|50.92665,5.592241|50.92524,5.682963|50.88491,5.677073|50.80597,5.646475|50.86802,5.734172|50.89124,5.594845|50.82225,5.771378</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (SuperBuf)]]></author>
			<pubDate>Mon, 25 Jul 2016 15:42:28 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=916#p916</guid>
		</item>
	</channel>
</rss>
