How to detect UI text input effectively to call google places API for suggestions?

268 views Asked by At

what is the best way to detect user input in a UItextfield to call places API for suggestions as user type ? Currently how i did is, after 3 letters i call the places API for every single letter input. But if user types 4 to 5 letters very fast app crashes, may be because of too much networking or something.

Take example of google maps app or google search app in ios. How do they decide at what point to call api to show results of suggestion? Sometimes user types very fast, sometimes they do letter by letter.

Apologise if my question is silly.

ios autocomplete search

2

There are 2 answers

0
AndrewR On BEST ANSWER

It's hard to be sure without seeing your code but I'd suspect that the crashes are being caused by updating UI controls in non-UI threads.

As you have discovered, there are subtleties to making requests as the user types (making too many requests, requests returning out of order etc.). Consider using the GMSAutocompleteFetcher class from the Google Places iOS SDK, which deals with these problems automatically.

0
schmidt9 On

Refer to this option by Google https://developers.google.com/places/ios-api/autocomplete. I have not tried it, maybe it can help.