<?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 — script for calculate distance to a multiple marks in map.]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1655</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1655&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in script for calculate distance to a multiple marks in map..]]></description>
		<lastBuildDate>Sun, 11 Jul 2021 11:10:25 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7580#p7580</link>
			<description><![CDATA[<p>In this case, the problem is that your MarkerIcons is not UI element and does not contain RectTransform.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sun, 11 Jul 2021 11:10:25 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7580#p7580</guid>
		</item>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7579#p7579</link>
			<description><![CDATA[<p>using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using UnityEngine;<br />using UnityEngine.UI;</p><p>namespace InfinityCode.OnlineMapsDemos<br />{<br />&nbsp; &nbsp; public class CustomMarkersEngineV5 : MonoBehaviour<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; private List&lt;MarkerInstance&gt; markers;<br />&nbsp; &nbsp; &nbsp; &nbsp; public RectTransform containerCanvas;<br />&nbsp; &nbsp; &nbsp; &nbsp; public GameObject MarkerIcons;<br />&nbsp; &nbsp; &nbsp; &nbsp; public Options Using;<br />&nbsp; &nbsp; &nbsp; &nbsp; public Vector2 UserGPS;<br />&nbsp; &nbsp; &nbsp; &nbsp; private Vector2 SensorGPS;<br />&nbsp; &nbsp; &nbsp; &nbsp; public MarkerData[] datas;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private Canvas canvas;<br />&nbsp; &nbsp; &nbsp; &nbsp; private OnlineMaps map;<br />&nbsp; &nbsp; &nbsp; &nbsp; private OnlineMapsTileSetControl control;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private float longitude;<br />&nbsp; &nbsp; &nbsp; &nbsp; private float latitude;<br />&nbsp; &nbsp; &nbsp; &nbsp; public float longitudeGPS;<br />&nbsp; &nbsp; &nbsp; &nbsp; public float latitudeGPS;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private float distance;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private Camera worldCamera<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (canvas.renderMode == RenderMode.ScreenSpaceOverlay) return null;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return canvas.worldCamera;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void OnEnable()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; canvas = containerCanvas.GetComponentInParent&lt;Canvas&gt;();<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void SetText(RectTransform rt, string childName, string value)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Transform child = rt.Find(childName);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (child == null) return;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Text t = child.gameObject.GetComponent&lt;Text&gt;();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (t != null) t.text = value;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void Start()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; map = OnlineMaps.instance;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; control = OnlineMapsTileSetControl.instance;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; map.OnMapUpdated += UpdateMarkers;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsCameraOrbit.instance.OnCameraControl += UpdateMarkers;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markers = new List&lt;MarkerInstance&gt;();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (MarkerData data in datas)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GameObject markerGameObject = Instantiate(MarkerIcons) as GameObject;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markerGameObject.name = data.title;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RectTransform rectTransform = markerGameObject.transform as RectTransform;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rectTransform.SetParent(containerCanvas);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markerGameObject.transform.localScale = Vector3.one;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MarkerInstance marker = new MarkerInstance();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.data = data;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.gameObject = markerGameObject;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.transform = rectTransform;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (markers.Any(m =&gt; m.data == data))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance = OnlineMapsUtils.DistanceBetweenPoints(UserGPS, marker.data.MarkerGPS).magnitude; //this not work in unity editor (show value 0), because PC dont have a GPS Sensor<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.data.DistanceKM.text = distance.ToString(&quot;F1&quot;) + &quot; KM&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markers.Add(marker);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetText(rectTransform, &quot;Title&quot;, data.title);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetText(rectTransform, &quot;cellphoneNumber&quot;, data.cellphoneNumber);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetText(rectTransform, &quot;emailAdress&quot;, data.emailAdress);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MarkersInMap();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateMarkers();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InvokeRepeating(&quot;UpdateLocation&quot;, 2.0f, 1.0f); //initiate function in 2 seconds after start, and repeat it every 1 seconds.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void MarkersInMap()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (MarkerData data in datas)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MarkerInstance marker = new MarkerInstance();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.data = data;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (markers.Any(m =&gt; m.data == data))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distance = OnlineMapsUtils.DistanceBetweenPoints(UserGPS, marker.data.MarkerGPS).magnitude;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.data.DistanceKM.text = distance.ToString(&quot;F1&quot;) + &quot; KM&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markers.Add(marker);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateMarkers();<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void UpdateMarkers()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (MarkerInstance marker in markers) UpdateMarker(marker);<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void UpdateMarker(MarkerInstance marker)<br />&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector2 screenPosition = control.GetScreenPosition(marker.data.MarkerGPS.y, marker.data.MarkerGPS.x); // y is inverted with x because shows the cordinares incorrectly if X axis is at firt.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (screenPosition.x &lt; 0 || screenPosition.x &gt; Screen.width ||<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; screenPosition.y &lt; 0 || screenPosition.y &gt; Screen.height)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; marker.gameObject.SetActive(false);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RectTransform markerRectTransform = marker.transform;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!marker.gameObject.activeSelf) marker.gameObject.SetActive(true);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector2 point;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RectTransformUtility.ScreenPointToLocalPointInRectangle(markerRectTransform.parent as RectTransform, screenPosition, worldCamera, out point);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; markerRectTransform.localPosition = point;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><br /><p>&nbsp; &nbsp; &nbsp; &nbsp; private void UpdateLocation()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (Using)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case Options.Simulator:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MarkersInMap(); //I used this function here just for test in unity editor.</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case Options.gpsSensor:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetLocationGPS();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MarkersInMap();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Debug.Log(&quot;use gps sensor&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void GetLocationGPS()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; longitude = Input.location.lastData.longitude;&nbsp; &nbsp; //get last longitude from GPS Sensor<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; latitude = Input.location.lastData.latitude;&nbsp; &nbsp; &nbsp; //get last latitude from GPS Sensor<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SensorGPS = new Vector2(latitude, longitude);&nbsp; //store the longitude &amp; latitude from GPS sensor in a Vector2<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UserGPS = SensorGPS;&nbsp; //copy the gps sensor cordinares for use in distance updates.</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; longitudeGPS = SensorGPS.x;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; latitudeGPS = SensorGPS.y;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; public enum Options<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Simulator,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gpsSensor<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; [Serializable]<br />&nbsp; &nbsp; &nbsp; &nbsp; public class MarkerData<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public string title;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public string cellphoneNumber;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public string emailAdress;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public Vector2 MarkerGPS;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public Text DistanceKM;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; public class MarkerInstance<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public MarkerData data;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public GameObject gameObject;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public RectTransform transform;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}</p><p>i was using this script only which was mentioned above getting error at line 69</p>]]></description>
			<author><![CDATA[null@example.com (ashh21411)]]></author>
			<pubDate>Sun, 11 Jul 2021 05:20:29 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7579#p7579</guid>
		</item>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7577#p7577</link>
			<description><![CDATA[<p>This is a bug in your script.<br />rectTransform is null.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sat, 10 Jul 2021 10:56:57 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7577#p7577</guid>
		</item>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7575#p7575</link>
			<description><![CDATA[<p>getting an error NullReferenceException: Object reference not set to an instance of an object<br />InfinityCode.OnlineMapsDemos.dist.Start () (at Assets/dist.cs:69) </p><p>line no 69 is this&nbsp; &nbsp; rectTransform.SetParent(containerCanvas);</p>]]></description>
			<author><![CDATA[null@example.com (ashh21411)]]></author>
			<pubDate>Fri, 09 Jul 2021 12:45:01 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7575#p7575</guid>
		</item>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6982#p6982</link>
			<description><![CDATA[<p>In MarkersInMap, why would you create a marker?<br />Also, you don&#039;t even need a check.<br /></p><div class="codebox"><pre><code>private void MarkersInMap()
{
  foreach (MarkerData data in datas)
  {
    distance = OnlineMapsUtils.DistanceBetweenPoints(UserGPS, data.MarkerGPS).magnitude;
    data.DistanceKM.text = distance.ToString(&quot;F1&quot;) + &quot; KM&quot;;
  }
  UpdateMarkers();
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 03 Dec 2020 22:29:00 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6982#p6982</guid>
		</item>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6981#p6981</link>
			<description><![CDATA[<p>@Alex Vertax<br />Thanks, its working now, I dont see any problems.<br />I updated the code in my post, If you want to point something for make improvements.</p><p>A doubt, is possible what the markers created by this script cant be scaled when I zooming the map?.</p>]]></description>
			<author><![CDATA[null@example.com (elfasito)]]></author>
			<pubDate>Thu, 03 Dec 2020 20:29:33 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6981#p6981</guid>
		</item>
		<item>
			<title><![CDATA[Re: script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6976#p6976</link>
			<description><![CDATA[<p>Hello.</p><p>You have two ways:<br />1. (Recommended) Check that the marker with the current data is already in the list.<br /></p><div class="codebox"><pre><code>if (markers.Any(m =&gt; m.data == data)) 
{
  // update distance and continue
  continue;
}</code></pre></div><p>2. At the beginning of MarkersInMap remove all markers.</p><p>P.S. You cannot work with GPS in the editor because you are using the Unity Location Service.<br />Use Online Maps Location Service instead. It has a GPS emulator and you will be able to debug your application in the editor.</p><p>P.P.S. In MarkersInMap, move the UpdateMarkers call outside of the foreach.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 03 Dec 2020 12:05:59 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6976#p6976</guid>
		</item>
		<item>
			<title><![CDATA[script for calculate distance to a multiple marks in map.]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6975#p6975</link>
			<description><![CDATA[<p>Hello im triying to create a script for add multiple markers to the map and calculate the distance from gps to all markers at the same time.</p><p>seeing the atlas examples I do some progress but im stuck now.</p><p>I want to update the distance to the markers what already exist in the list, getting the cordinares from gps sensor.</p><p>my main problem is I cant update the distance to the markers in each itineration, the function just duplicate the markers each itineration.</p><p><strong>EDIT: SOLVED, new code solution:</strong><br /></p><div class="codebox"><pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace InfinityCode.OnlineMapsDemos
{
    public class CustomMarkersEngineV5 : MonoBehaviour
    {
        private List&lt;MarkerInstance&gt; markers;
        public RectTransform containerCanvas;
        public GameObject MarkerIcons;
        public Options Using;
        public Vector2 UserGPS;
        private Vector2 SensorGPS;
        public MarkerData[] datas;

        private Canvas canvas;
        private OnlineMaps map;
        private OnlineMapsTileSetControl control;

        private float longitude;
        private float latitude;
        public float longitudeGPS;
        public float latitudeGPS;

        private float distance;

        private Camera worldCamera
        {
            get
            {
                if (canvas.renderMode == RenderMode.ScreenSpaceOverlay) return null;
                return canvas.worldCamera;
            }
        }

        private void OnEnable()
        {
            canvas = containerCanvas.GetComponentInParent&lt;Canvas&gt;();
        }

        private void SetText(RectTransform rt, string childName, string value)
        {
            Transform child = rt.Find(childName);
            if (child == null) return;

            Text t = child.gameObject.GetComponent&lt;Text&gt;();
            if (t != null) t.text = value;
        }

        private void Start()
        {
            map = OnlineMaps.instance;
            control = OnlineMapsTileSetControl.instance;

            map.OnMapUpdated += UpdateMarkers;
            OnlineMapsCameraOrbit.instance.OnCameraControl += UpdateMarkers;

            markers = new List&lt;MarkerInstance&gt;();

            foreach (MarkerData data in datas)
            {
                GameObject markerGameObject = Instantiate(MarkerIcons) as GameObject;
                markerGameObject.name = data.title;
                RectTransform rectTransform = markerGameObject.transform as RectTransform;
                rectTransform.SetParent(containerCanvas);
                markerGameObject.transform.localScale = Vector3.one;
                MarkerInstance marker = new MarkerInstance();
                marker.data = data;
                marker.gameObject = markerGameObject;
                marker.transform = rectTransform;
                if (markers.Any(m =&gt; m.data == data))
                {
                    distance = OnlineMapsUtils.DistanceBetweenPoints(UserGPS, marker.data.MarkerGPS).magnitude; //this not work in unity editor (show value 0), because PC dont have a GPS Sensor
                    marker.data.DistanceKM.text = distance.ToString(&quot;F1&quot;) + &quot; KM&quot;;
                    continue;
                }
                markers.Add(marker);
                SetText(rectTransform, &quot;Title&quot;, data.title);
                SetText(rectTransform, &quot;cellphoneNumber&quot;, data.cellphoneNumber);
                SetText(rectTransform, &quot;emailAdress&quot;, data.emailAdress);
            }

            MarkersInMap();
            UpdateMarkers();
            InvokeRepeating(&quot;UpdateLocation&quot;, 2.0f, 1.0f); //initiate function in 2 seconds after start, and repeat it every 1 seconds.                        
        }

        private void MarkersInMap()
        {
            foreach (MarkerData data in datas)
            {
                MarkerInstance marker = new MarkerInstance();
                marker.data = data;
                if (markers.Any(m =&gt; m.data == data))
                {
                    distance = OnlineMapsUtils.DistanceBetweenPoints(UserGPS, marker.data.MarkerGPS).magnitude;
                    marker.data.DistanceKM.text = distance.ToString(&quot;F1&quot;) + &quot; KM&quot;;
                    continue;
                }
                markers.Add(marker);                             
            }
            UpdateMarkers();
        }

        private void UpdateMarkers()
        {
            foreach (MarkerInstance marker in markers) UpdateMarker(marker);
        }

        private void UpdateMarker(MarkerInstance marker)
        {            
            Vector2 screenPosition = control.GetScreenPosition(marker.data.MarkerGPS.y, marker.data.MarkerGPS.x); // y is inverted with x because shows the cordinares incorrectly if X axis is at firt.
            if (screenPosition.x &lt; 0 || screenPosition.x &gt; Screen.width ||
                screenPosition.y &lt; 0 || screenPosition.y &gt; Screen.height)
            {
                marker.gameObject.SetActive(false);
                return;
            }

            RectTransform markerRectTransform = marker.transform;

            if (!marker.gameObject.activeSelf) marker.gameObject.SetActive(true);

            Vector2 point;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(markerRectTransform.parent as RectTransform, screenPosition, worldCamera, out point);
            markerRectTransform.localPosition = point;
        }


        private void UpdateLocation()
        {
            switch (Using)
            {
                case Options.Simulator:
                    MarkersInMap(); //I used this function here just for test in unity editor.

                    break;

                case Options.gpsSensor:
                    GetLocationGPS();
                    MarkersInMap();
                    //Debug.Log(&quot;use gps sensor&quot;);

                    break;
            }
        }

        private void GetLocationGPS()
        {
            longitude = Input.location.lastData.longitude;    //get last longitude from GPS Sensor
            latitude = Input.location.lastData.latitude;      //get last latitude from GPS Sensor
            SensorGPS = new Vector2(latitude, longitude);  //store the longitude &amp; latitude from GPS sensor in a Vector2
            UserGPS = SensorGPS;  //copy the gps sensor cordinares for use in distance updates.

            longitudeGPS = SensorGPS.x;
            latitudeGPS = SensorGPS.y;
        }

        public enum Options
        {
            Simulator,
            gpsSensor
        }

        [Serializable]
        public class MarkerData
        {
            public string title;
            public string cellphoneNumber;
            public string emailAdress;
            public Vector2 MarkerGPS;
            
            public Text DistanceKM;
        }

        public class MarkerInstance
        {
            public MarkerData data;
            public GameObject gameObject;
            public RectTransform transform;
        }
    }
}</code></pre></div><br /><p>Im using this function:<br /></p><div class="codebox"><pre><code>switch (Using)
            {
                case Options.Simulator:
                    MarkersInMap(); //I used this function here just for test in unity editor.
                    break;</code></pre></div><p>to simulate the iterations from gps sensor. If I disable it go works fine in editor, because only itinerates one time (Start function).</p><p>maybe my explanation is a bit unclear, I will try to rewrite, if it is not understandable.</p>]]></description>
			<author><![CDATA[null@example.com (elfasito)]]></author>
			<pubDate>Thu, 03 Dec 2020 11:51:58 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6975#p6975</guid>
		</item>
	</channel>
</rss>
