问题
I am using google API - places to autocomplete locations in AutoCompleteTextView
. I did couple of tests maybe 20 searches and in my profile on google devs, it's written that I have made 200 API requests.
I understand that it is making request every time I type something or edit typed text. But is there any way how to reduce amount of calls to server?
One of ideas is to define threshold to 3 characters.
回答1:
I think a better implementation to reduce the number of calls to the Places API would be to put in a delay of maybe 0.75 seconds after the last key-press. That would avoid confusion on the part of a user who after seeing autocomplete after 3 letters, sits and waits after typing his 5th.
回答2:
If you did not find a better solutions( I know it is very late, but I am doing something similar and I found my self in here.)
I think you can "cache" previous results, put them in ArrayList. And then in your adapter when performFiltering is called, start by checking the results you have in your Arraylist and if you receive a number of similar items, dont make a request to the API. I am not sure if it is clear but you can at least save a couple requests like that and for the user side, the autocomplete is always refreshing.
I hope it helps.
来源:https://stackoverflow.com/questions/27916517/how-to-minimize-amount-of-requests-for-google-api-places-autocomplete