2
votes

I am trying to implement an autocomplete box that looks like the google maps iOS app. In that app, the suggestions are sorted by distance with a label on the left showing the distance. I presume they are using the Places Autocomplete API but I can't get it to return the distance. Is there some sort of flag I can use to have the autocomplete function of Google Places return distance from device? Am I using the wrong API/function?

I am currently using the following function:

autocompleteQuery:bounds:filter:callback:

Documentation is here:

https://developers.google.com/places/ios-api/autocomplete

1

1 Answers

2
votes

There's no way that you can get distance information directly in the autocomplete response.

I'd recommend performing a details request for each place in the response using lookUpPlaceID. Then you can access the coordinate field of the returned place to work out the distance.

If you do this asynchronously, you can update your UI with the autocomplete predictions when they return and then update it again with the distance once the details request completes.