Topic: Google Places Autocomplete returns last value
Hi
I'm using the AutocompleteApi from google,example from Atlas of examples.
The problem is that when i search a place, it always returns the last placa i searched, even after restarting editor in play mode.
This is the code i'm using based on the example:
public class AutocompleteAPIsearch : MonoBehaviour
{
/// <summary>
/// Google API Key
/// </summary>
public string apiKey;
private string placestring, types, language, components;
Vector2 lnglat;
int offset, radius;
public InputField inputfield;
public GameObject placeButton, transformada;
OnlineMapsGooglePlacesAutocompleteResult[] results;
public void autocomplete()
{
placestring = inputfield.text;
offset = -1;
types = null;
lnglat = default(Vector2);
radius = -1;
if (LeanLocalization.CurrentLanguage == "Portuguese") language = "pt";
if (LeanLocalization.CurrentLanguage == "English") language = "en";
components = "country:" + language;
Debug.Log(components);
//lnglat = new Vector2(OnlineMapsLocationService.instance.position.x, OnlineMapsLocationService.instance.position.y);
// Makes a request to Google Places Autocomplete API. See the reference in OnlineMaps Api Reference
OnlineMapsGooglePlacesAutocomplete.Find(
placestring,
apiKey,
types,
offset,
lnglat,
radius,
language,
components
).OnComplete += OnComplete;
}
/// <summary>
/// This method is called when a response is received.
/// </summary>
/// <param name="s">Response string</param>
private void OnComplete(string s)
{
// Trying to get an array of results.
results = OnlineMapsGooglePlacesAutocomplete.GetResults(s);
//results = results.Distinct().ToArray();
// If there is no result
if (results == null)
{
Debug.Log("Error");
Debug.Log(s);
return;
}
else
{
// Log description of each result.
// foreach (OnlineMapsGooglePlacesAutocompleteResult result in results)
for (int i = 0; i < results.Length; i++)
{
Instantiate(placeButton, transformada.transform);
placeButton.GetComponentInChildren<Text>().text = results[i].description;
Debug.Log(results[i].description);
}
}
}
I always get the last place, but the strangest thing is that in the debug console, the name of the place is correct, and doesnt show the last place name.