<?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 — Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=868</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=868&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Reverse method LatLongToMercat in OnlineMapsUtils.]]></description>
		<lastBuildDate>Sat, 28 Jul 2018 17:39:49 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3734#p3734</link>
			<description><![CDATA[<p>You mean the distance between the points?<br />You need to convert the Mercator&#039;s position to geographic coordinates, and use OnlineMapsUtils.DistanceBetweenPoints.</p><p>If you meant something else, please show the code so I understand what you are trying to calculate.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sat, 28 Jul 2018 17:39:49 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3734#p3734</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3733#p3733</link>
			<description><![CDATA[<p>More question.<br />Can I also use the Mercator coordinates to calculate the distance? As you(0,6082588; y = 0,3596105) figures in Mercator does not match with OSM (5006688б,4702653). I&#039;ve always counted the distance in Mercator meters. And these calculations don&#039;t match yours. It just turns out that the radius calculated for the Mercator meters using OSM methods is 1.3 times greater than your radius.<br />And I on the server need to calculate the distance as easy as possible.</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Sat, 28 Jul 2018 17:07:07 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3733#p3733</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3732#p3732</link>
			<description><![CDATA[<p>Cool there explain) I would have been 2 years ago) I came up with my map architecture. This information on the link I see for the first time) But the map was completed) And the plug-ins in the assetstore have more features. I was looking in the assetstore then, and apparently then there were no 2d cards, only 3d. Or badly looking)</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Sat, 28 Jul 2018 02:14:16 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3732#p3732</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3731#p3731</link>
			<description><![CDATA[<p>OSM uses tangent, I use this formula (LatLongToPixelXY method) that uses the sine:<br /><a href="https://msdn.microsoft.com/en-us/library/bb259689.aspx">https://msdn.microsoft.com/en-us/library/bb259689.aspx</a><br />But in fact we have the same result.<br />Look at the screenshot (attached). The building is absolutely in the same place where it is painted in OSM.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 27 Jul 2018 23:37:44 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3731#p3731</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3730#p3730</link>
			<description><![CDATA[<p>I drew at Unity3D at home in 3D on top of the openstreetmap tile map, where houses are painted. So I needed an absolutely exact conversion. I also remember the problem of the mismatch between my 3D homes and houses on tiles closer to the poles.</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Fri, 27 Jul 2018 23:10:03 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3730#p3730</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3729#p3729</link>
			<description><![CDATA[<p>It turns out they have these methods in all the major languages.<br /><a href="https://wiki.openstreetmap.org/wiki/Mercator">https://wiki.openstreetmap.org/wiki/Mercator</a></p><p>Look at &quot;C# implementation&quot;</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Fri, 27 Jul 2018 23:07:29 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3729#p3729</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3728#p3728</link>
			<description><![CDATA[<p>Unfortunately, I do not understand what meters you mean.</p><p>Usually the following terms are used in maps:<br />Geographical coordinates, tile coordinates (tile position), Mercator coordinates.<br />Meters are used for distances. But this is not used for internal calculations.</p><p>Most likely you mean the tile coordinates.<br />You can always convert double to int (or long), if you only need to know the tile index.<br />But you can not convert int to double to find out where exactly in the tile is some kind of coordinate.</p><p>Using of double is not a bottleneck and does not have any significant effect on performance and memory usage in 99.9% of applications.<br />So using double has only positive sides.</p><div class="quotebox"><blockquote><p>The methods for C # from OpenStreetMap...</p></blockquote></div><p>What is it? <br />I could not find anything suitable in Google.<br />Please send me a link. It is very interesting to me.</p><div class="quotebox"><blockquote><p>All the others, no matter what I try, give excellent results, and as a result, the results are not correct, including your convertation methods too) How so?)</p></blockquote></div><p>I&#039;m not sure I understand what you meant.<br />You mean that (for example) by converting geographic coordinates into tile coordinates, and then converting back you have a slightly different result, right?<br />This is a floating-point error.<br />But it is small enough to ignore it.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 27 Jul 2018 20:45:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3728#p3728</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3727#p3727</link>
			<description><![CDATA[<p>Alex Vertax, you&#039;re right! I 2 years ago from scratch wrote a map based on tiles from OpenStreetMap and used a meters in type Int. I wonder why you use double? This is in fact just a type that is more demanding on memory. Or is it about optimizing internal computation, by using double, instead of int?<br />And the question. For some reason, each coordinate conversion system &quot;gps to mercator&quot; produces different results. The methods for C # from OpenStreetMap give exactly and exactly the same results as expected when converting. All the others, no matter what I try, give excellent results, and as a result, the results are not correct, including your convertation methods too) How so?)<br />Even on node.js I could not find the library of conversion, which would give the same results. Therefore, on the server I do not convert the coordinates, but I trust this to the client, because only on the client methods C # from OpenStreetMap</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Fri, 27 Jul 2018 19:59:36 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3727#p3727</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3726#p3726</link>
			<description><![CDATA[<p>I made a test script and it works correctly.<br />Script:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class TestMercatToLngLat : MonoBehaviour
{
    private void Start()
    {
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }

    private void OnMapClick()
    {
        Vector2 coords = OnlineMapsControlBase.instance.GetCoords();
        Debug.Log(coords.ToString(&quot;F4&quot;));
        Vector2 mercat = OnlineMapsUtils.LatLongToMercat(coords.x, coords.y);
        Debug.Log(mercat.ToString(&quot;F4&quot;));
        double x, y;
        OnlineMapsUtils.MercatToLatLong(mercat.x, mercat.y, out x, out y);
        Debug.Log(x + &quot;  &quot; + y);
    }
}</code></pre></div><p>Output:<br /></p><div class="codebox"><pre><code>(-9.7852, 13.2383) // Coords
(0.4728, 0.4629) // Mercator (0-1)
-9.78522352874279  13.2382842992934 // Coords</code></pre></div><p>Perhaps you pass incorrect data to the method.<br />This requires a position in the Mercator projection (0-1).</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 27 Jul 2018 18:23:37 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3726#p3726</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3725#p3725</link>
			<description><![CDATA[<p>Unfortunately, the method does not work correctly.<br /></p><div class="codebox"><pre><code>    public static (double, double) MercatToLatLong(float mx, float my) {
        uint mapSize = (uint)tileSize &lt;&lt; 20;
        double px = Clip(mx * mapSize + 0.5, 0, mapSize - 1);
        double py = Clip(my * mapSize + 0.5, 0, mapSize - 1);
        mx = (float)(px / tileSize);
        my = (float)(py / tileSize);
        TileToLatLong(mx, my, 20, out double x, out double y);
        return (x, y);
    }</code></pre></div><p>Should return approximately 38,97316; 45,02914, and returns -179.999998658895; -85,0511286641139</p><p>Help!)</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Fri, 27 Jul 2018 14:00:40 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3725#p3725</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3723#p3723</link>
			<description><![CDATA[<p>Alex Vertax, thx!</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Fri, 27 Jul 2018 12:57:28 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3723#p3723</guid>
		</item>
		<item>
			<title><![CDATA[Re: Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3719#p3719</link>
			<description><![CDATA[<p>Hello.</p><p>This method is not used in internal calculations, and no one ever asked about it.<br />Something like:<br /></p><div class="codebox"><pre><code>public static void MercatToLatLong(double mx, double my, out double x, out double y)
{
    uint mapSize = (uint)tileSize &lt;&lt; 20;
    double px = Clip(mx * mapSize + 0.5, 0, mapSize - 1);
    double py = Clip(my * mapSize + 0.5, 0, mapSize - 1);
    mx = px / tileSize;
    my = py / tileSize;
    TileToLatLong(mx, my, 20, out x, out y);
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 26 Jul 2018 21:01:22 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3719#p3719</guid>
		</item>
		<item>
			<title><![CDATA[Reverse method LatLongToMercat in OnlineMapsUtils]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=3716#p3716</link>
			<description><![CDATA[<p>Hello!</p><p>I need a method to reverse this. Tell me, please, how to do this? It&#039;s strange that the plugin does not have this method.</p><p>You need to convert gps Mercator to LonLat</p><p>&nbsp; &nbsp; public static Vector2 LatLongToMercat(float x, float y)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; float sy = Mathf.Sin(y * Mathf.Deg2Rad);<br />&nbsp; &nbsp; &nbsp; &nbsp; return new Vector2((x + 180) / 360, 0.5f - Mathf.Log((1 + sy) / (1 - sy)) / pi4);<br />&nbsp; &nbsp; }</p>]]></description>
			<author><![CDATA[null@example.com (NovaEiz)]]></author>
			<pubDate>Thu, 26 Jul 2018 14:07:22 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=3716#p3716</guid>
		</item>
	</channel>
</rss>
