<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Map lost]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2325&amp;type=atom" />
	<updated>2024-11-13T01:06:10Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2325</id>
		<entry>
			<title type="html"><![CDATA[Re: Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9730#p9730" />
			<content type="html"><![CDATA[<p>i found the reason that make the map disappeared .<br />i have a <br />1-GameObject A with Panel as child<br />here i used a button to set gameobject with map as child ACTIVE<br />BUT I DONT DISACTIVE&nbsp; GAMEOBJECT A. <br />i Make it out of focus :<br /> float leftMargin = 9350f;&nbsp; // Adjust the left margin<br />&nbsp; &nbsp; &nbsp; &nbsp; float rightMargin = -9350f; // Adjust the right margin <br />&nbsp; &nbsp; &nbsp; &nbsp; RectTransform rectTransform = RoomHandlr.GetComponent&lt;RectTransform&gt;();<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMin = new Vector2(leftMargin, rectTransform.offsetMin.y);<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMax = new Vector2(-rightMargin, rectTransform.offsetMax.y);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; rectTransform = StartHandlr.GetComponent&lt;RectTransform&gt;();<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMin = new Vector2(leftMargin, rectTransform.offsetMin.y);<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMax = new Vector2(-rightMargin, rectTransform.offsetMax.y);</p><br /><p> CAUSE I NEED IT FOR GETTING VARIABLE <br />so having this situation causing map to be dragged. <br />if i desactive gameobject A its work perfectly . but i need gameobject A.</p>]]></content>
			<author>
				<name><![CDATA[tamim.ali.zoabi]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1098</uri>
			</author>
			<updated>2024-11-13T01:06:10Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9730#p9730</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9729#p9729" />
			<content type="html"><![CDATA[<p>It&#039;s very strange. <br />First of all, restart the editor. <br />I&#039;ve heard that this sometimes helps with this problem.</p><p>If the problem persists, you need to isolate the request to which service is causing the problem.<br />Then send your request to me and I&#039;ll see what I can do about it.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2024-11-12T20:08:53Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9729#p9729</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9727#p9727" />
			<content type="html"><![CDATA[<p>i add this script to GameObject in the hierarchy but i still got same error when i change compase value or Position Value&quot;Longitude,Latitude&quot; in gps emulater</p>]]></content>
			<author>
				<name><![CDATA[tamim.ali.zoabi]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1098</uri>
			</author>
			<updated>2024-11-11T21:11:11Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9727#p9727</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9726#p9726" />
			<content type="html"><![CDATA[<p>This is a known issue in Unity, and is solved this way:<br /></p><div class="codebox"><pre><code>using UnityEngine;
using UnityEngine.Networking;

public class X509Hook : MonoBehaviour
{
    public void Start()
    {
        OnlineMapsWWW.OnCreateRequest += r =&gt; r.request.certificateHandler = new AllowHandler();
    }
    
    private class AllowHandler : CertificateHandler
    {
        protected override bool ValidateCertificate(byte[] certificateData)
        {
            return true;
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2024-11-11T20:24:07Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9726#p9726</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9725#p9725" />
			<content type="html"><![CDATA[<p>I do a debug and a gps emulation&nbsp; <br />So approximately when the map change position i got this error : Curl error 60: Cert verify failed: UNITYTLS_X509VERIFY_FLAG_USER_ERROR1</p>]]></content>
			<author>
				<name><![CDATA[tamim.ali.zoabi]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1098</uri>
			</author>
			<updated>2024-11-11T10:54:14Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9725#p9725</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9724#p9724" />
			<content type="html"><![CDATA[<p>I don&#039;t know why your map was destroyed.<br />This script does not destroy objects.<br />Check your other scripts.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2024-11-10T18:38:03Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9724#p9724</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Map lost]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9722#p9722" />
			<content type="html"><![CDATA[<p>i got this code from Smooth GPS move.cs from your reaply for some one and add some functions for car speed etc. <br />this code is going correct but suddenly the map or the instance of the map destroyed or disappeared , what causing that .</p><p>using System;<br />using System.Collections;<br />using System.Collections.Generic;<br />using UnityEngine;<br />using UnityEngine.UI;<br />using LastPositionItem = OnlineMapsLocationService.LastPositionItem;</p><p>public class MarkerAtBottom : MonoBehaviour<br />{<br />&nbsp; &nbsp; public GameObject RoomHandler, StartHandler, GpsHandler;<br />&nbsp; &nbsp; public OnlineMapsControlBase3D control;<br />&nbsp; &nbsp; public float zoomLevel = 16;<br />&nbsp; &nbsp; public GameObject prefab;<br />&nbsp; &nbsp; public Text text;<br />&nbsp; &nbsp; public float rotationSpeed = 0.5f;<br />&nbsp; &nbsp; public float resetDelay = 5f;</p><p>&nbsp; &nbsp; private Vector2 currentLocation;<br />&nbsp; &nbsp; public OnlineMapsMarker3D locationMarker;<br />&nbsp; &nbsp; private float initialXRotation;<br />&nbsp; &nbsp; private Coroutine resetPositionCoroutine;<br />&nbsp; &nbsp; private OnlineMaps map;<br />&nbsp; &nbsp; private bool isUserInteracting;<br />&nbsp; &nbsp; OnlineMapsLocationService ls;</p><p>&nbsp; &nbsp; public float sensitivity = 0.4f; // Controls how much the gyro input affects rotation<br />&nbsp; &nbsp; public Text SpeedText;</p><p>&nbsp; &nbsp; private float moveStartTime;</p><br /><p>&nbsp; &nbsp; public float lowPassFilterFactor = 0.1f; // Low-pass filter factor for additional stability</p><br /><p>&nbsp; &nbsp; Quaternion initialRotation; // To keep track of the initial orientation<br />&nbsp; &nbsp; private Vector2 startPosition, endPosition;<br />&nbsp; &nbsp; private float startTime;<br />&nbsp; &nbsp; private float endTime;<br />&nbsp; &nbsp; private float halfSecondTimer = 0f;<br />&nbsp; &nbsp; private float oneSecondTimer = 0f;<br />&nbsp; &nbsp; private float halfSecondInterval = 0.5f;<br />&nbsp; &nbsp; private float oneSecondInterval = 1f;</p><p>&nbsp; &nbsp; //-------------------------------------------------<br />&nbsp; &nbsp; public float correctionTime = 0.5f;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Should the map position be updated?<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; public bool updateMapPosition = true;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Smooth changes in compass values<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; public bool lerpCompassValue = true;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Reference to Location Service<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private OnlineMapsLocationService locationService;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Current speed (km/h)<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private float speed;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Compass true heading (degree)<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private float compass;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Last known location<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private OnlineMapsVector2d lastKnownLocation;</p><br /><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Correction vector<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private OnlineMapsVector2d correction;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Reference to the marker<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private OnlineMapsMarker marker;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// List of last positions<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private List&lt;LastPositionItem&gt; lastPositions;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// The maximum number of items in the list of last positions<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private int maxPositionCount = 3;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Progress of correction<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private float correctionProgress;</p><p>&nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; /// Smoothed compass value (degree)<br />&nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; private float smoothedCompass;<br />&nbsp; &nbsp; //-------------------------------------------------<br />&nbsp; &nbsp; public Button Btn;<br />&nbsp; &nbsp; private void Start()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; if (control == null) control = OnlineMapsControlBase3D.instance;<br />&nbsp; &nbsp; &nbsp; &nbsp; if (control == null)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.text = &quot;You must use the 3D control (Texture or Tileset).&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; if (SystemInfo.supportsGyroscope)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Input.gyro.enabled = true;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initialRotation = Quaternion.Euler(90, 0, 0); // Adjust based on map orientation<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; map = OnlineMaps.instance;<br />&nbsp; &nbsp; &nbsp; &nbsp; // Subscribe to map interaction events<br />&nbsp; &nbsp; &nbsp; &nbsp; map.OnMapUpdated += OnMapInteraction;<br />&nbsp; &nbsp; &nbsp; &nbsp; map.OnChangeZoom += OnMapInteraction;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ls = OnlineMapsLocationService.instance;<br />&nbsp; &nbsp; &nbsp; &nbsp; Input.location.Start();<br />&nbsp; &nbsp; &nbsp; &nbsp; Input.compass.enabled = true;<br />&nbsp; &nbsp; &nbsp; &nbsp; if (ls == null)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text.text = &quot;Location Service not found.&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ls.OnLocationInited += OnLocationInited;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Store the initial X rotation of the map to preserve it<br />&nbsp; &nbsp; &nbsp; &nbsp; initialXRotation = map.transform.eulerAngles.x;<br />&nbsp; &nbsp; &nbsp; &nbsp; moveStartTime = Time.time;</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; private void OnLocationInited()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; currentLocation = new Vector2(Input.location.lastData.longitude, Input.location.lastData.latitude);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Create the marker at the current location<br />&nbsp; &nbsp; &nbsp; &nbsp; locationMarker = control.marker3DManager.Create(currentLocation, prefab);<br />&nbsp; &nbsp; &nbsp; &nbsp; //locationMarker.transform.localScale = Vector3.one * 22f;&nbsp; // Adjust scale for better visibility<br />&nbsp; &nbsp; &nbsp; &nbsp; locationMarker.scale = 16f;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; ls.OnLocationChanged += OnLocationChanged;<br />&nbsp; &nbsp; &nbsp; &nbsp; ls.OnCompassChanged += OnCompassChanged;<br />&nbsp; &nbsp; &nbsp; &nbsp; lastKnownLocation = currentLocation = ls.position;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; private void OnCompassChanged(float compassHeading)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // 888<br />&nbsp; &nbsp; &nbsp; &nbsp; //////// Rotate the marker based on compass heading<br />&nbsp; &nbsp; &nbsp; &nbsp; //////if (locationMarker != null)<br />&nbsp; &nbsp; &nbsp; &nbsp; //////{<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; Transform markerTransform = locationMarker.transform;<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; if (markerTransform != null)<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; &nbsp; &nbsp; markerTransform.rotation = Quaternion.Euler(0, compassHeading, 0);<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; //////}<br />&nbsp; &nbsp; &nbsp; &nbsp; ///<br />&nbsp; &nbsp; &nbsp; &nbsp; // Update compass value<br />&nbsp; &nbsp; &nbsp; &nbsp; compass = compassHeading * 360;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // If the marker rotation should not smooth, update the rotation<br />&nbsp; &nbsp; &nbsp; &nbsp; if (!lerpCompassValue &amp;&amp; locationMarker != null) locationMarker.rotationY = compassHeading;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; private void Update()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // 88<br />&nbsp; &nbsp; &nbsp; &nbsp; //////if (Input.gyro.enabled)<br />&nbsp; &nbsp; &nbsp; &nbsp; //////{<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; // Get the Y-axis rotation rate from the gyroscope<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; float gyroY = Input.gyro.rotationRateUnbiased.y;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; // Apply a low-pass filter to stabilize small movements<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; filteredYRotation = (1 - lowPassFilterFactor) * filteredYRotation + lowPassFilterFactor * gyroY;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; // Apply smoothing to the filtered Y rotation rate and accumulate in yRotation<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; yRotation += filteredYRotation * sensitivity;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; // Smooth the transition by using Lerp on the rotation itself<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; map.transform.rotation = Quaternion.Lerp(map.transform.rotation, Quaternion.Euler(0, yRotation, 0), smoothFactor);<br />&nbsp; &nbsp; &nbsp; &nbsp; //////}</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (speed &lt; 1 || locationMarker == null) return;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Smooth changes of compass<br />&nbsp; &nbsp; &nbsp; &nbsp; if (lerpCompassValue)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (compass - smoothedCompass &gt; 180) smoothedCompass += 360;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else if (compass - smoothedCompass &lt; -180) smoothedCompass -= 360;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Math.Abs(compass - smoothedCompass) &gt;= float.Epsilon)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Mathf.Abs(compass - smoothedCompass) &lt; 0.003f) smoothedCompass = compass;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else smoothedCompass = Mathf.Lerp(smoothedCompass, compass, 0.02f);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; locationMarker.rotationY = smoothedCompass;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Find the expected location<br />&nbsp; &nbsp; &nbsp; &nbsp; float coveredDistance = Time.deltaTime * speed / 3600f;<br />&nbsp; &nbsp; &nbsp; &nbsp; double lng, lat;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsUtils.GetCoordinateInDistance(currentLocation.x, currentLocation.y, coveredDistance, compass, out lng, out lat);<br />&nbsp; &nbsp; &nbsp; &nbsp; currentLocation.x = (float)lng;<br />&nbsp; &nbsp; &nbsp; &nbsp; currentLocation.y = (float)lat;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // If correction is required, do it<br />&nbsp; &nbsp; &nbsp; &nbsp; if (correctionProgress &lt; 1 &amp;&amp; correction.SqrMagnitude() &gt; 0)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float nextCorrectionProgress = correctionProgress + Time.deltaTime / correctionTime;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (nextCorrectionProgress &gt; 1) nextCorrectionProgress = 1;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float correctionDelta = nextCorrectionProgress - correctionProgress;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentLocation.x += (float)correction.x * correctionDelta;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentLocation.y += (float)correction.y * correctionDelta;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; correctionProgress = nextCorrectionProgress;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Set marker position<br />&nbsp; &nbsp; &nbsp; &nbsp; locationMarker.SetPosition(lng, lat);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Set map position<br />&nbsp; &nbsp; &nbsp; &nbsp; if (updateMapPosition) OnlineMaps.instance.SetPosition(lng, lat);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Increment timers by the time passed since last frame<br />&nbsp; &nbsp; &nbsp; &nbsp; halfSecondTimer += Time.deltaTime;<br />&nbsp; &nbsp; &nbsp; &nbsp; oneSecondTimer += Time.deltaTime;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Call function every 0.5 seconds<br />&nbsp; &nbsp; &nbsp; &nbsp; if (halfSecondTimer &gt;= halfSecondInterval)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FunctionEveryHalfSecond();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; halfSecondTimer = 0f; // Reset the timer<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Call function every 1 second<br />&nbsp; &nbsp; &nbsp; &nbsp; if (oneSecondTimer &gt;= oneSecondInterval)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FunctionEverySecond();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oneSecondTimer = 0f; // Reset the timer<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; }<br />&nbsp; &nbsp; public void UpdateSpeed()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; if (lastPositions == null) lastPositions = new List&lt;LastPositionItem&gt;();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; lastPositions.Add(new LastPositionItem((float)lastKnownLocation.x, (float)lastKnownLocation.y, Time.time));<br />&nbsp; &nbsp; &nbsp; &nbsp; while (lastPositions.Count &gt; maxPositionCount) lastPositions.RemoveAt(0);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (lastPositions.Count &lt; 2)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speed = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; LastPositionItem p1 = lastPositions[0];<br />&nbsp; &nbsp; &nbsp; &nbsp; LastPositionItem p2 = lastPositions[lastPositions.Count - 1];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; double dx, dy;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsUtils.DistanceBetweenPoints(p1.lng, p1.lat, p2.lng, p2.lat, out dx, out dy);<br />&nbsp; &nbsp; &nbsp; &nbsp; double distance = Math.Sqrt(dx * dx + dy * dy);<br />&nbsp; &nbsp; &nbsp; &nbsp; double time = (p2.timestamp - p1.timestamp) / 3600;<br />&nbsp; &nbsp; &nbsp; &nbsp; speed = Mathf.Abs((float)(distance / time));<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; void FunctionEveryHalfSecond()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;Function called every 0.5 seconds&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; SetStartPosition();<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; void FunctionEverySecond()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log(&quot;Function called every 1 second&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; SetEndPosition();<br />&nbsp; &nbsp; &nbsp; &nbsp; CalculateSpeed();<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; private void OnLocationChanged(Vector2 newLocation)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // 88<br />&nbsp; &nbsp; &nbsp; &nbsp; //////if (locationMarker != null)<br />&nbsp; &nbsp; &nbsp; &nbsp; //////{<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; locationMarker.position = position;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; // Update the current location for display<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; currentLocation = position;<br />&nbsp; &nbsp; &nbsp; &nbsp; //////&nbsp; &nbsp; //text.text = &quot;3-Longitude: &quot; + currentLocation.x.ToString(&quot;F6&quot;) + &quot; Latitude: &quot; + currentLocation.y.ToString(&quot;F6&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; //////}<br />&nbsp; &nbsp; &nbsp; &nbsp; ///<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Save a new location<br />&nbsp; &nbsp; &nbsp; &nbsp; lastKnownLocation = newLocation;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Calculating the correction vector<br />&nbsp; &nbsp; &nbsp; &nbsp; correction = lastKnownLocation - currentLocation;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Update current speed<br />&nbsp; &nbsp; &nbsp; &nbsp; UpdateSpeed();</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Calculate a distance between new and old locations<br />&nbsp; &nbsp; &nbsp; &nbsp; double dx, dy;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsUtils.DistanceBetweenPoints(newLocation.x, newLocation.y, currentLocation.x, currentLocation.y, out dx, out dy);<br />&nbsp; &nbsp; &nbsp; &nbsp; double d = Math.Sqrt(dx * dx + dy * dy);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // If the distance is too long or the speed is too low, update the location<br />&nbsp; &nbsp; &nbsp; &nbsp; if (d &gt; 0.01 || speed &lt; 1)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentLocation = lastKnownLocation;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; correction = OnlineMapsVector2d.zero;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Reset correction progress<br />&nbsp; &nbsp; &nbsp; &nbsp; correctionProgress = 0;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; private void OnMapInteraction()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // Flag to indicate user interaction to prevent compass-based rotation updates<br />&nbsp; &nbsp; &nbsp; &nbsp; isUserInteracting = true;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Restart coroutine to reset position after delay<br />&nbsp; &nbsp; &nbsp; &nbsp; if (resetPositionCoroutine != null) StopCoroutine(resetPositionCoroutine);<br />&nbsp; &nbsp; &nbsp; &nbsp; resetPositionCoroutine = StartCoroutine(ResetPositionAfterDelay());<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; private IEnumerator ResetPositionAfterDelay()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // Wait for the delay<br />&nbsp; &nbsp; &nbsp; &nbsp; yield return new WaitForSeconds(resetDelay);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Reset the map position and zoom level<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMaps.instance.SetPositionAndZoom(currentLocation.x, currentLocation.y, zoomLevel);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Reset user interaction flag to resume compass-based rotation<br />&nbsp; &nbsp; &nbsp; &nbsp; isUserInteracting = false;<br />&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; void SetStartPosition()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // Get the starting position (latitude, longitude)<br />&nbsp; &nbsp; &nbsp; &nbsp; startPosition =new Vector2( locationMarker.position.x,locationMarker.position.y); // Example start position<br />&nbsp; &nbsp; &nbsp; &nbsp; startTime = Time.time;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; void SetEndPosition()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; endTime = Time.time;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; void CalculateSpeed()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; // Calculate distance in kilometers between start and end positions<br />&nbsp; &nbsp; &nbsp; &nbsp; double distanceKm = OnlineMapsUtils.DistanceBetweenPoints(startPosition, locationMarker.position).magnitude;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Calculate time taken in hours<br />&nbsp; &nbsp; &nbsp; &nbsp; double timeHours = (endTime - startTime) / 3600.0;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Calculate speed in km/h<br />&nbsp; &nbsp; &nbsp; &nbsp; double speed = distanceKm / timeHours;<br />&nbsp; &nbsp; &nbsp; &nbsp; SpeedText.text = speed.ToString();<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log($&quot;Distance traveled: {distanceKm} km&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log($&quot;Time taken: {timeHours} hours&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; Debug.Log($&quot;Calculated Speed: {speed} km/h&quot;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; // Reset start position for continuous speed tracking (optional)<br />&nbsp; &nbsp; &nbsp; &nbsp; startPosition = endPosition;<br />&nbsp; &nbsp; &nbsp; &nbsp; startTime = endTime;</p><p>&nbsp; &nbsp; }<br />&nbsp; &nbsp; public void GoToRoomChat()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; float leftMargin = 0; <br />&nbsp; &nbsp; &nbsp; &nbsp; float rightMargin = 0; <br />&nbsp; &nbsp; &nbsp; &nbsp; RectTransform rectTransform = RoomHandler.GetComponent&lt;RectTransform&gt;();<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMin = new Vector2(leftMargin, rectTransform.offsetMin.y);<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMax = new Vector2(-rightMargin, rectTransform.offsetMax.y);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; rectTransform = StartHandler.GetComponent&lt;RectTransform&gt;();<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMin = new Vector2(leftMargin, rectTransform.offsetMin.y);<br />&nbsp; &nbsp; &nbsp; &nbsp; rectTransform.offsetMax = new Vector2(-rightMargin, rectTransform.offsetMax.y);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; GpsHandler.SetActive(false);<br />&nbsp; &nbsp; }<br />}</p>]]></content>
			<author>
				<name><![CDATA[tamim.ali.zoabi]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1098</uri>
			</author>
			<updated>2024-11-10T10:33:55Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9722#p9722</id>
		</entry>
</feed>
