<?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 — Best practice geofencing]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1575</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1575&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Best practice geofencing.]]></description>
		<lastBuildDate>Thu, 06 Aug 2020 16:40:41 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Best practice geofencing]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6534#p6534</link>
			<description><![CDATA[<p>Hello.</p><p>Three points about CalculcateDistance method:</p><p>1. DistanceBetweenPoints is a very slow method and it is best to minimize its use. <br />To do this, first calculate the distance in degrees between locations. <br />If the distance in degrees is less than 12 arc minutes (for example, 1/5 degree, ~360 meters) then use DistanceBetweenPoints to calculate the distance in kilometers.</p><p>2. For a correct result, it doesn&#039;t matter whether you calculate the distance in meters or kilometers.<br />If you calculate the distance in kilometers, you will save one multiplication per marker.</p><p>3. By using sqrMagnitude instead of magnitude, you will save Math.Sqrt per marker.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 06 Aug 2020 16:40:41 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6534#p6534</guid>
		</item>
		<item>
			<title><![CDATA[Re: Best practice geofencing]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6533#p6533</link>
			<description><![CDATA[<p>First working example with the same mindset as what I did with Mapbox:</p><div class="codebox"><pre><code>using UnityEngine;

public class UnlockingManager : MonoBehaviour
{
    [Header(&quot;Variables&quot;)]
    [Tooltip(&quot;Distance needed to unlock points in meters.&quot;)]
    public float distanceNeeded = 25f;

    private OnlineMapsLocationService locationService;
    private CreateMarkers markers;

    private void Start()
    {
        locationService = OnlineMapsLocationService.instance;
        markers = FindObjectOfType&lt;CreateMarkers&gt;();
        locationService.OnLocationChanged += CalculcateDistance;
    }

    private void CalculcateDistance(Vector2 location)
    {
        string closest_location = string.Empty;
        float closest_distance = 9999;
        foreach (OnlineMapsMarker3D marker in markers.spawned_objects)
        {
            float distance = OnlineMapsUtils.DistanceBetweenPoints(location, marker.position).magnitude * 1000;
            if(distance &lt; closest_distance)
            {
                closest_distance = distance;
                closest_location = marker.label;
            }
            if (distanceNeeded &gt; distance) Debug.Log($&quot;{marker.label} unlocked!&quot;);
        }
        Debug.Log($&quot;Closest location is {closest_location}, {closest_distance} meters away!&quot;);
    }
}</code></pre></div><p>I&#039;m pretty sure this isn&#039;t best practice, since it might take a lot of performance to do these calculations (I haven&#039;t tested it yet, let alone test it with a large set (40+ 3d markers)), but for now it works.<br />Still, if there is some kind of best practice I should be looking into I&#039;d love to know!</p>]]></description>
			<author><![CDATA[null@example.com (jarne)]]></author>
			<pubDate>Thu, 06 Aug 2020 12:42:09 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6533#p6533</guid>
		</item>
		<item>
			<title><![CDATA[Best practice geofencing]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6532#p6532</link>
			<description><![CDATA[<p>I&#039;m wondering what the best practice for geofencing would be.<br />What I want is for when my user to walk a route with 3d markers scattered on it and entering an X radius (10-200m) of said markers that they &quot;unlock&quot; it.</p><p>I&#039;ve seen some geofencing examples and examples with BoxCollider, but I&#039;m wondering what the best practice is for this kind of behaviour? And if there is an example that I can look at to get an idea of what to do.</p><p>I used to do this in Mapbox by calculating the distance between geo location of player and closest marker object in the scene. I&#039;ve tried doing the same in my current project with Online Maps, but it seems that I&#039;m doing something wrong with the OnlineMapsUtils.DistanceBetweenPoints (I keep getting 0 as the distance between two points, I think it&#039;s because they get transferred into doubles and lose the rest of the decimals, which makes the lat/lng &quot;identical&quot;).</p><p>Any help would be appreciated!</p><p>I&#039;m using 3d markers and the LocationServices player marker if that&#039;s important to know.</p><p>p.s. so far I&#039;m loving this plugin, a lot of useful features and examples that I can chop into custom things to use.</p><p>Edit:<br />I&#039;ve found this: <a href="http://infinity-code.com/atlas/online-maps/pages/DistanceAndDirectionExample.html">http://infinity-code.com/atlas/online-m … ample.html</a><br />Which I can rewrite to do what I want to achieve, but it this the best practice?</p>]]></description>
			<author><![CDATA[null@example.com (jarne)]]></author>
			<pubDate>Thu, 06 Aug 2020 11:28:31 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6532#p6532</guid>
		</item>
	</channel>
</rss>
