<?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 — Tile To Coordinates with float zoom]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1317</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1317&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Tile To Coordinates with float zoom.]]></description>
		<lastBuildDate>Fri, 02 Aug 2019 13:01:27 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Tile To Coordinates with float zoom]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5398#p5398</link>
			<description><![CDATA[<p>Hello.</p><p>Your link does not contain scripts.<br />Your code is insufficient for testing.</p><p>I understand correctly that you want to draw a circle with a radius in meters?<br />Example of how to do this:<br /></p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class DrawCircleAroundMarker : MonoBehaviour
{
    public float radiusKM = 0.1f;
    public int segments = 32;

    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }

    private void OnMapClick()
    {
        double lng, lat;
        OnlineMapsControlBase.instance.GetCoords(out lng, out lat);

        OnlineMapsMarkerManager.CreateItem(lng, lat, &quot;Marker &quot; + OnlineMapsMarkerManager.CountItems);

        OnlineMaps map = OnlineMaps.instance;
        
        double nlng, nlat;
        OnlineMapsUtils.GetCoordinateInDistance(lng, lat, radiusKM, 90, out nlng, out nlat);

        double tx1, ty1, tx2, ty2;
        map.projection.CoordinatesToTile(lng, lat, 20, out tx1, out ty1);
        map.projection.CoordinatesToTile(nlng, nlat, 20, out tx2, out ty2);

        double r = tx2 - tx1;

        OnlineMapsVector2d[] points = new OnlineMapsVector2d[segments];

        double step = 360d / segments;

        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);
        }

        OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingPoly(points, Color.red, 3));
    }
}</code></pre></div><p>Please note that when using Drawing API, you do not need to update points when changing the position or zoom of the map.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 02 Aug 2019 13:01:27 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5398#p5398</guid>
		</item>
		<item>
			<title><![CDATA[Tile To Coordinates with float zoom]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5397#p5397</link>
			<description><![CDATA[<p>Hi, I am making an app that shows some pois on the map and then draws a circle around each poi with its range (The user has to be inside the range to interact with it).</p><p>The circles have a fixed radius that has to be refreshed accordingly with the zoom of the map, I use a code that I found in this post:<br /><a href="http://forum.infinity-code.com/viewtopic.php?pid=3651#p3651">http://forum.infinity-code.com/viewtopi … 3651#p3651</a></p><p>My code:</p><div class="codebox"><pre><code>private void UpdatePoiRangeCircle(MyMarker myMarker)
    {
        OnlineMaps mapInstance = OnlineMaps.instance;
        Vector2 distanceBetweenTileCorners = OnlineMapsUtils.DistanceBetweenPoints(mapInstance.topLeftPosition, mapInstance.bottomRightPosition);
        float radiusInPixels = (myMarker.poi.range / 1000f) * OnlineMapsTileSetControl.instance.sizeInScene.x / distanceBetweenTileCorners.x;
        float r = radiusInPixels / OnlineMapsUtils.tileSize;

        float step = 360f / poiCircleSegments;
        double x, y;
        myMarker.OMmarcador.GetPosition(out x, out y);
        OnlineMapsProjection projection = mapInstance.projection;
        projection.CoordinatesToTile(x, y, mapInstance.zoom, out x, out y);

        for (int i = 0; i &lt; poiCircleSegments; i++)
        {
            double px = x + Mathf.Cos(step * i * Mathf.Deg2Rad) * r;
            double py = y + Mathf.Sin(step * i * Mathf.Deg2Rad) * r;

            // Old way (Online Maps v2.3):
            // OnlineMapsUtils.TileToLatLong(px, py, map.zoom, out px, out py);

            projection.TileToCoordinates(px, py, mapInstance.zoom, out px, out py);

            myMarker.poiCircle.points[i] = new Vector2((float)px, (float)py);
        }

    }</code></pre></div><p>This works fine but the problem is that when zooming in or out the circle doesn&#039;t update correctly until it reaches an int value of the zoom.</p><p>I attached a video of what&#039;s happening.</p><p>Is there any way to get the coordinates from tile position using a float zoom instead of an int zoom?</p>]]></description>
			<author><![CDATA[null@example.com (adrian.blanco)]]></author>
			<pubDate>Fri, 02 Aug 2019 10:44:12 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5397#p5397</guid>
		</item>
	</channel>
</rss>
