<?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 — Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1587</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1587&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Update position (lat,lng) of drawn OnlineMapsDrawingElement.]]></description>
		<lastBuildDate>Thu, 20 Aug 2020 12:32:40 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6598#p6598</link>
			<description><![CDATA[<p>I got it, thank you so much for your help and sorry if my questions are noob-ish.</p>]]></description>
			<author><![CDATA[null@example.com (jarne)]]></author>
			<pubDate>Thu, 20 Aug 2020 12:32:40 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6598#p6598</guid>
		</item>
		<item>
			<title><![CDATA[Re: Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6596#p6596</link>
			<description><![CDATA[<p>Hello.</p><p>It doesn&#039;t work that way.<br />You need to update every point of the polygon, and call map.Redraw.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 20 Aug 2020 11:30:46 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6596#p6596</guid>
		</item>
		<item>
			<title><![CDATA[Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6593#p6593</link>
			<description><![CDATA[<p>Hi,</p><p>I&#039;m trying to update the position of a drawn OnlineMapsDrawingElement so it sticks to the player (LocationService).<br />I thought I had it with this code: <a href="https://forum.infinity-code.com/viewtopic.php?pid=6536#p6536">https://forum.infinity-code.com/viewtop … 6536#p6536</a> </p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class DrawCircleAroundPlayer : MonoBehaviour
{
    /// &lt;summary&gt;
    /// Radius of the circle
    /// &lt;/summary&gt;
    public float radiusKM = 0.1f;

    /// &lt;summary&gt;
    /// Number of segments
    /// &lt;/summary&gt;
    public int segments = 32;

    private OnlineMapsMarker3DInstance onlineMapsMarker;
    private OnlineMaps map;

    private void Start()
    {
        map = OnlineMaps.instance;
        onlineMapsMarker = GetComponent&lt;OnlineMapsMarker3DInstance&gt;();
        name = onlineMapsMarker.marker.label;
        DrawCircle();
    }

    /// &lt;summary&gt;
    /// Draw circle around player with set radius
    /// &lt;/summary&gt;
    private void DrawCircle()
    {
        // Get the coordinates under cursor
        double lng = onlineMapsMarker.marker.position.x;
        double lat = onlineMapsMarker.marker.position.y;

        // Get the coordinate at the desired distance
        double nlng, nlat;
        OnlineMapsUtils.GetCoordinateInDistance(lng, lat, radiusKM, 90, out nlng, out nlat);

        double tx1, ty1, tx2, ty2;

        // Convert the coordinate under cursor to tile position
        map.projection.CoordinatesToTile(lng, lat, 20, out tx1, out ty1);

        // Convert remote coordinate to tile position
        map.projection.CoordinatesToTile(nlng, nlat, 20, out tx2, out ty2);

        // Calculate radius in tiles
        double r = tx2 - tx1;

        // Create a new array for points
        OnlineMapsVector2d[] points = new OnlineMapsVector2d[segments];

        // Calculate a step
        double step = 360d / segments;

        // Calculate each point of circle
        for (int i = 0; i &lt; segments; i++)
        {
            double px = tx1 + Math.Cos(step * i * OnlineMapsUtils.Deg2Rad) * r;
            double py = ty1 + Math.Sin(step * i * OnlineMapsUtils.Deg2Rad) * r;
            map.projection.TileToCoordinates(px, py, 20, out lng, out lat);
            points[i] = new OnlineMapsVector2d(lng, lat);
        }

        // Create a new polygon to draw a circle
        OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(points, Color.green, 3));
    }
}</code></pre></div><p>however the circle stays in place (which is fairly logical since it&#039;s not really updated to follow the player).</p><p>I&#039;ve tried to adjust the transform.position of the drawn circle with:<br /></p><div class="codebox"><pre><code>item.instance.transform.position = OnlineMapsTileSetControl.instance.GetWorldPosition(position);</code></pre></div><p>with the position coming for the &quot;OnLocationChanged&quot; event.</p><p>What am I doing wrong? How should I go about changing the position of the draw circle to follow the player?<br />I&#039;ve tried setting the parent of the circle to the PlayerMarker, yet this also gives some weird behaviour.</p>]]></description>
			<author><![CDATA[null@example.com (jarne)]]></author>
			<pubDate>Thu, 20 Aug 2020 11:03:21 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6593#p6593</guid>
		</item>
	</channel>
</rss>
