<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1587&amp;type=atom" />
	<updated>2020-08-20T12:32:40Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1587</id>
		<entry>
			<title type="html"><![CDATA[Re: Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6598#p6598" />
			<content type="html"><![CDATA[<p>I got it, thank you so much for your help and sorry if my questions are noob-ish.</p>]]></content>
			<author>
				<name><![CDATA[jarne]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1355</uri>
			</author>
			<updated>2020-08-20T12:32:40Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6598#p6598</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6596#p6596" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-08-20T11:30:46Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6596#p6596</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Update position (lat,lng) of drawn OnlineMapsDrawingElement]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=6593#p6593" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[jarne]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1355</uri>
			</author>
			<updated>2020-08-20T11:03:21Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=6593#p6593</id>
		</entry>
</feed>
