<?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 — MapBox Search]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1839</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1839&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in MapBox Search.]]></description>
		<lastBuildDate>Fri, 17 Sep 2021 10:32:40 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: MapBox Search]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7724#p7724</link>
			<description><![CDATA[<p>Thank you Alex</p>]]></description>
			<author><![CDATA[null@example.com (artpen)]]></author>
			<pubDate>Fri, 17 Sep 2021 10:32:40 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7724#p7724</guid>
		</item>
		<item>
			<title><![CDATA[Re: MapBox Search]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7718#p7718</link>
			<description><![CDATA[<p>I updated the script in post 2.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 16 Sep 2021 11:28:17 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7718#p7718</guid>
		</item>
		<item>
			<title><![CDATA[Re: MapBox Search]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7717#p7717</link>
			<description><![CDATA[<p>Thank you Alex.<br />Works great only one time <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />It throws an error at me when I try to search for second location</p><p>NullReferenceException: Object reference not set to an instance of an object<br />InfinityCode.OnlineMapsDemos.MapboxSearchPanel.OnGeocodingComplete (OnlineMapsWWW www) (at Assets/Scripts/MapboxSearchPanel.cs:49)</p>]]></description>
			<author><![CDATA[null@example.com (artpen)]]></author>
			<pubDate>Thu, 16 Sep 2021 08:19:00 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7717#p7717</guid>
		</item>
		<item>
			<title><![CDATA[Re: MapBox Search]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7713#p7713</link>
			<description><![CDATA[<p>Hello.</p><p>Actually, it&#039;s very easy.<br />Example:<br /></p><div class="codebox"><pre><code>using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace InfinityCode.OnlineMapsDemos
{
    [AddComponentMenu(&quot;Infinity Code/Online Maps/Demos/Mapbox Search Panel&quot;)]
    public class MapboxSearchPanel : MonoBehaviour
    {
        public InputField inputField;
        private OnlineMapsMarker marker;

        public void Search()
        {
            if (!OnlineMapsKeyManager.hasMapbox)
            {
                Debug.LogWarning(&quot;Please enter Map / Key Manager / Mapbox&quot;);
                return;
            }

            if (inputField == null) return;
            if (inputField.text.Length &lt; 3) return;

            string locationName = OnlineMapsWWW.EscapeURL(inputField.text);
            string key = OnlineMapsKeyManager.Mapbox();

            OnlineMapsWWW www = new OnlineMapsWWW($&quot;https://api.mapbox.com/geocoding/v5/mapbox.places/{locationName}.json?access_token={key}&quot;);
            www.OnComplete += OnGeocodingComplete;
        }

        private void OnGeocodingComplete(OnlineMapsWWW www)
        {
            if (www.hasError)
            {
                Debug.Log(www.error);
                return;
            }

            OnlineMapsJSONItem json = OnlineMapsJSON.Parse(www.text);

            OnlineMapsJSONItem feature = json[&quot;features/0&quot;];
            OnlineMapsJSONItem centerJSON = feature[&quot;center&quot;];
            Vector2 centerPoint = new Vector2(centerJSON[0].V&lt;float&gt;(), centerJSON[1].V&lt;float&gt;());

            if (marker == null) marker = OnlineMapsMarkerManager.CreateItem(centerPoint);
            else
            {
                marker.position = centerPoint;
            }

            marker.label = feature[&quot;place_name&quot;].V&lt;string&gt;();

            OnlineMapsJSONItem bbox = feature[&quot;bbox&quot;];
            Vector2 topLeft = new Vector2(bbox[0].V&lt;float&gt;(), bbox[1].V&lt;float&gt;());
            Vector2 bottomRight = new Vector2(bbox[2].V&lt;float&gt;(), bbox[3].V&lt;float&gt;());

            Vector2 center;
            int zoom;
            OnlineMapsUtils.GetCenterPointAndZoom(new Vector2[] { topLeft, bottomRight }, out center, out zoom);
            OnlineMaps.instance.SetPositionAndZoom(centerPoint.x, centerPoint.y, zoom);
        }

        private void Update()
        {
            EventSystem eventSystem = EventSystem.current;
            if ((Input.GetKeyUp(KeyCode.KeypadEnter) || Input.GetKeyUp(KeyCode.Return)) &amp;&amp; eventSystem.currentSelectedGameObject == inputField.gameObject)
            {
                Search();
            }
        }
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 15 Sep 2021 20:03:24 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7713#p7713</guid>
		</item>
		<item>
			<title><![CDATA[MapBox Search]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=7707#p7707</link>
			<description><![CDATA[<p>Hi guys,<br />Does anyone has an example for search using Mapbox geocoding?<br />I tried to edit SearchPanel script, but I think I am doing it wrong.</p><p>I found attached script on Mapbox webpage. But not sure how to transfer it to Online Maps.</p><p>Thank you for help </p><div class="codebox"><pre><code>public class ForwardGeocodeUserSearch : MonoBehaviour
    {
        TMP_InputField _inputField;

        ForwardGeocodeResource _resource;

        Vector2d _coordinate;
        public Vector2d Coordinate
        {
            get
            {
                return _coordinate;
            }
        }

        bool _hasResponse;
        public bool HasResponse
        {
            get
            {
                return _hasResponse;
            }
        }

        public ForwardGeocodeResponse Response { get; private set; }

        public event Action&lt;ForwardGeocodeResponse&gt; OnGeocoderResponse = delegate { };

        void Awake()
        {
            _inputField = GetComponent&lt;TMP_InputField&gt;();
            _inputField.onEndEdit.AddListener(HandleUserInput);
            _resource = new ForwardGeocodeResource(&quot;&quot;);
        }

        void HandleUserInput(string searchString)
        {
            _hasResponse = false;
            if (!string.IsNullOrEmpty(searchString))
            {
                _resource.Query = searchString;
                MapboxAccess.Instance.Geocoder.Geocode(_resource, HandleGeocoderResponse);
            }
        }

        void HandleGeocoderResponse(ForwardGeocodeResponse res)
        {
            _hasResponse = true;
            if (null == res)
            {
                _inputField.text = &quot;no geocode response&quot;;
            }
            else if (null != res.Features &amp;&amp; res.Features.Count &gt; 0)
            {
                var center = res.Features[0].Center;
                _coordinate = res.Features[0].Center;
            }
            Response = res;
            OnGeocoderResponse(res);
        }
    }</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (artpen)]]></author>
			<pubDate>Wed, 15 Sep 2021 09:14:13 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=7707#p7707</guid>
		</item>
	</channel>
</rss>
