How can I minimize the number of requests for autocomplete API (places) Google API?

I am using google API - Autocomplete locations in AutoCompleteTextView

. I did a couple of tests, maybe 20 searches and in my profile at google devs, it wrote that I made 200 API requests.

I understand that it makes a request every time I type something or edit text. But is there a way to reduce the number of calls to the server?

One idea is to define a threshold of up to 3 characters.

+3


source to share


2 answers


I think the best implementation to reduce the number of calls to the Places API would be to delay, perhaps 0.75 seconds after the last key press. This will avoid confusion on the part of the user who, after viewing autocomplete after three letters, sits and waits after entering their 5th.



+1


source


If you haven't found a better solution (I know it's very late, but I'm doing something similar and I found myself here).

I think you can "cache" the previous results, put them in an ArrayList. And then in your adapter, when the Execute function is called, start by checking the results that you have in your Arraylist, and if you get multiple similar items, don't make a request to the API. I'm not sure if this is clear, but you can at least keep a couple of queries like this and for the user, autocomplete is always refreshing.



Hope this helps.

+1


source







All Articles