<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — GPX Line car]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2110&amp;type=atom" />
	<updated>2023-04-23T11:47:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2110</id>
		<entry>
			<title type="html"><![CDATA[Re: GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9000#p9000" />
			<content type="html"><![CDATA[<p>The code above does what you are asked about.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-04-23T11:47:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9000#p9000</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8999#p8999" />
			<content type="html"><![CDATA[<p>Thanks Alex for the example. I can get the distance with the slider value between two coordinates that I use as a test but how can I add an indicator ( game object ) that shows the position of the slider value on the map line (line render gpx) ?</p>]]></content>
			<author>
				<name><![CDATA[LazzLab]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=669</uri>
			</author>
			<updated>2023-04-22T15:44:29Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8999#p8999</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8998#p8998" />
			<content type="html"><![CDATA[<p>Thanks Alex.</p>]]></content>
			<author>
				<name><![CDATA[LazzLab]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=669</uri>
			</author>
			<updated>2023-04-21T16:29:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8998#p8998</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8996#p8996" />
			<content type="html"><![CDATA[<p>Sure, here&#039;s the code:<br /></p><div class="codebox"><pre><code>/// &lt;summary&gt;
/// Current progress value (0-1)
/// &lt;/summary&gt;
public float progress;
    
/// &lt;summary&gt;
/// Points of the route
/// &lt;/summary&gt;
private OnlineMapsVector2d[] points;

private void UpdateMarkerPosition()
{
    // Calculate the total distance of the route.
    double totalDistanceKm = 0;
    for (int i = 0; i &lt; points.Length - 1; i++)
    {
        OnlineMapsVector2d p1 = points[i];
        OnlineMapsVector2d p2 = points[i + 1];
        totalDistanceKm += OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, 0, p2.x, p2.y, 0);
    }
    
    // Calculate the distance covered.
    double coveredDistanceKm = totalDistanceKm * Mathf.Clamp01(progress);

    for (int i = 0; i &lt; points.Length - 1; i++)
    {
        // Calculate the distance between the current and next point.
        OnlineMapsVector2d p1 = points[i];
        OnlineMapsVector2d p2 = points[i + 1];
        double distance = OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, 0, p2.x, p2.y, 0);
        
        // If the distance covered is greater than the distance between the current and next point,
        // subtract the distance between the current and next point from the distance covered.
        if (coveredDistanceKm &gt; distance)
        {
            coveredDistanceKm -= distance;
        }
        // If the distance covered is less or equal than the distance between the current and next point,
        // calculate the position of the marker.
        else
        {
            double lng = p1.x + (p2.x - p1.x) * coveredDistanceKm / distance;
            double lat = p1.y + (p2.y - p1.y) * coveredDistanceKm / distance;
            marker.SetPosition(lng, lat);
            break;
        }
    }
}</code></pre></div><p>P.S. This is theoretical code and I have not tested it. I hope I wrote it without bugs.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-04-20T14:58:09Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8996#p8996</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8995#p8995" />
			<content type="html"><![CDATA[<p>Thanks Alex. Can you give me an example?</p>]]></content>
			<author>
				<name><![CDATA[LazzLab]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=669</uri>
			</author>
			<updated>2023-04-20T14:43:50Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8995#p8995</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8987#p8987" />
			<content type="html"><![CDATA[<p>Hi.</p><p>You need to calculate the total length of the route (add the lengths of all segments).<br />Based on the progress of your slider, the length of the route that the car has covered (total * progress).<br />Next, you need to find the segment (two points, AB, BC, CD, etc.) where the car is.<br />Go through all the segments of your route.<br />If the length of the segment is less than the covered length, subtract the length of the segment from the covered length.<br />If it is greater than or equal to, you have found the desired segment.<br />Next, you need to find a point on the segment.<br />This is very easy to do, just Lerp(a, b, coveredLength / segmentLength).</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-04-19T19:54:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8987#p8987</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[GPX Line car]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8986#p8986" />
			<content type="html"><![CDATA[<p>Hi Alex I hope all is well. I upload a GPX and redraw it with DrawingElement line on the 3d map. Everything OK. Request. How can I make a GameObject ( car ) move along the line with a ui slider ? Thank you</p>]]></content>
			<author>
				<name><![CDATA[LazzLab]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=669</uri>
			</author>
			<updated>2023-04-19T09:44:21Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8986#p8986</id>
		</entry>
</feed>
