<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Google Autocomplete API to get locations around the user's GPS?]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2122&amp;type=atom" />
	<updated>2023-06-07T13:49:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2122</id>
		<entry>
			<title type="html"><![CDATA[Re: Google Autocomplete API to get locations around the user's GPS?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9058#p9058" />
			<content type="html"><![CDATA[<p>The current version of Online Maps does not have an API for this service, but that does not mean that you cannot use it.<br />Make a request manually and process the response.<br />Something like:<br /></p><div class="codebox"><pre><code>using UnityEngine;

namespace InfinityCode.OnlineMapsSupport
{
    public class BingMapsAutocompleteExample : MonoBehaviour
    {
        private void Start()
        {
            string key = OnlineMapsKeyManager.BingMaps();
            string query = &quot;El bur&quot;;
            
            // This is wrong because you have to wait for the GPS to initialize,
            // and I did it here to minimize the complexity of the example.
            Vector2 userLocation = OnlineMapsLocationService.instance.position;
            
            string url = $&quot;https://dev.virtualearth.net/REST/v1/Autosuggest?query={OnlineMapsWWW.EscapeURL(query)}&amp;userLocation={userLocation.y},{userLocation.x},5&amp;includeEntityTypes=Business&amp;key={key}&quot;;
            OnlineMapsWWW www = new OnlineMapsWWW(url);
            www.OnComplete += OnRequestComplete;
        }
        
        private void OnRequestComplete(OnlineMapsWWW www)
        {
            if (www.hasError)
            {
                Debug.LogError(www.error);
                return;
            }

            OnlineMapsJSONItem json = OnlineMapsJSON.Parse(www.text);
            foreach (OnlineMapsJSONValue item in json[&quot;//formattedAddress&quot;])
            {
                Debug.Log(item.V&lt;string&gt;());
            }
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-06-07T13:49:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9058#p9058</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Google Autocomplete API to get locations around the user's GPS?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9057#p9057" />
			<content type="html"><![CDATA[<p>I see Bing Autocomplete solves this silly issue by providing full address details for all queries:</p><p><a href="https://learn.microsoft.com/en-us/bingmaps/rest-services/autosuggest">https://learn.microsoft.com/en-us/bingm … utosuggest</a></p><p>Would it be possible to add that to the API? This looks way way way better than Google&#039;s service. It has more structured address responses with street, country, postal code, etc. all separately defined. Google also requests you to put their logo on anything using their service which is just ugly. </p><p>Only thing Bing Autosuggest doesn&#039;t give automatically is GPS, which I believe we must then get with Location search:</p><p><a href="https://learn.microsoft.com/en-us/bingmaps/rest-services/locations/find-a-location-by-address">https://learn.microsoft.com/en-us/bingm … by-address</a><br /><a href="http://infinity-code.com/doxygen/online-maps/classOnlineMapsBingMapsLocation.html#a37caf0d2b68f8aa541972808b7c528d6">http://infinity-code.com/doxygen/online … 08b7c528d6</a></p><p>Thanks for any help.</p>]]></content>
			<author>
				<name><![CDATA[mikejm]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1782</uri>
			</author>
			<updated>2023-06-07T05:49:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9057#p9057</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Google Autocomplete API to get locations around the user's GPS?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9055#p9055" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>Hi.</p><p>I just tested the Autocomplete API with and without location, and it gives different results.<br />A screenshot is attached.<br />The location used is Rottweil, Germany.</p><p>What do you need to do to check what is wrong:<br />Add a Log component, and turn on Request Events.<br />Find the Autocomplete API request in the console, and check it in the browser.<br />If it&#039;s not correct, please let me know what&#039;s wrong and I&#039;ll make the necessary changes.<br />If it&#039;s correct, unfortunately, I can&#039;t help you, because it&#039;s a third party service, which I can&#039;t affect.</p></blockquote></div><p>Thanks Alex. I think I figured at least one part out. Google is designed to be inefficient to make you make multiple queries to get anything useful.</p><p><a href="https://stackoverflow.com/questions/59807235/google-maps-places-autocomplete-not-returning-street-numbers">https://stackoverflow.com/questions/598 … et-numbers</a></p><p>According to that we must take the placeID from each autocomplete suggestion and then do a Places Details query for each to get the actual addresses. Just a way for them to charge 5 times more for each result.</p><p><a href="http://infinity-code.com/doxygen/online-maps/classOnlineMapsGooglePlaceDetails.html">http://infinity-code.com/doxygen/online … tails.html</a></p>]]></content>
			<author>
				<name><![CDATA[mikejm]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1782</uri>
			</author>
			<updated>2023-06-07T03:48:10Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9055#p9055</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Google Autocomplete API to get locations around the user's GPS?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9048#p9048" />
			<content type="html"><![CDATA[<p>Hi.</p><p>I just tested the Autocomplete API with and without location, and it gives different results.<br />A screenshot is attached.<br />The location used is Rottweil, Germany.</p><p>What do you need to do to check what is wrong:<br />Add a Log component, and turn on Request Events.<br />Find the Autocomplete API request in the console, and check it in the browser.<br />If it&#039;s not correct, please let me know what&#039;s wrong and I&#039;ll make the necessary changes.<br />If it&#039;s correct, unfortunately, I can&#039;t help you, because it&#039;s a third party service, which I can&#039;t affect.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-05-29T15:40:28Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9048#p9048</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Google Autocomplete API to get locations around the user's GPS?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9047#p9047" />
			<content type="html"><![CDATA[<p>I have been able to implement the Autocomplete example as per this:</p><p><a href="https://infinity-code.com/atlas/online-maps/pages/FindAutocompleteExample.html">https://infinity-code.com/atlas/online- … ample.html</a></p><p>Google&#039;s API has a way to limit or focus the results by GPS as this is typically needed:</p><p><a href="https://developers.google.com/maps/documentation/places/web-service/autocomplete">https://developers.google.com/maps/docu … tocomplete</a></p><p>&quot;You may bias results to a specified circle by passing a location and a radius parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed.&quot;</p><p>I have tried using the following:</p><div class="codebox"><pre><code>OnlineMapsGooglePlacesAutocomplete.Params autoCompleteParams = new OnlineMapsGooglePlacesAutocomplete.Params {
                key = apiKey,
                location = currentLocation, //long,lat as Vector2
                radius = 10 * 1000, //meters (ie. km * 1000)
            };

            OnlineMapsGooglePlacesAutocomplete.Find(searchString, autoCompleteParams).OnComplete += autoCompleteReturned;</code></pre></div><p>However, this does not seem to be working properly. I am not getting reliably biased results to my area. I wonder if there some error in implementation.</p><p>For example, if I start typing my home address or a nearby address in, I am still getting very far away results unless I go very far with the typing to almost completely spell it out. Or if I type a chain like Starbucks or McDonald&#039;s or a gas station brand, I still find some far away results ahead of close ones. It is better than not giving any location or radius but still not as good as expected.</p><p>Can you test this on your end perhaps to confirm if it is working as expected or let me know if there&#039;s any easy way to test it objectively against Google&#039;s standard?</p><p>I also note that &quot;result.description&quot; tends to return addresses of places like this: &quot;McDonald&#039;s, Grace Street, City, Province/State, Country.&quot; ie. There is no street #. How do we get the full address with street #? </p><p>Is there a way to get the result broken down into these components like city, country, street number/name, facility name as separate fields? Also is GPS of the location stored in result too?</p><p>Thanks for your help.</p>]]></content>
			<author>
				<name><![CDATA[mikejm]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1782</uri>
			</author>
			<updated>2023-05-29T00:42:19Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9047#p9047</id>
		</entry>
</feed>
