Reputation: 538
Hi I have an app which uses Mapbox, I am also using geocoding to search places and to navigate to the location. It was working smoothly until I tried the keyword "Nayara" in the searchField.
I am getting this error when I search "Nayara" in the textfield, the textFieldIsChanging delegate is connected to the GeoCoding API(which is async communication and result is populated in the tableView). I can successfully search all other places but not this one. Is this a bug in the map box? Is this the only one keyword which has problems or are there any other keywords which makes the app behave like this? Expert advices needed. Thanks in advance. Happy coding.
Upvotes: 4
Views: 316
Reputation: 797
When making multiple async requests, it's possible for the responses to be returned in a different order from the order in which they were requested. This is particularly an issue when requests take a variable amount of time (as is the case for geocoding queries).
In this situation, a query for Nayar
probably takes longer than a query for Nayara
, and the difference is enough that the results arrive out of order, so the Nayar
response overwrites Nayara
in the UI dropdown.
Typical solutions to this problem involve either adding a debounce (so that you only make a new API request if an arbitrary amount of time has elapsed between keystrokes), or tracking the timestamp of both the request and the response, and discarding stale responses that arrive out of order.
An example of the latter approach can be seen here: https://github.com/mapbox/react-geocoder/pull/9
Upvotes: 1