Places Search results to sort based on distance in AutoCompleteSupportFragment

979 views Asked by At

I am checking for similar results as stated in this link ,it for server side Google Places Api sort by distance

I need to sort the places based on my nearest distance of mobile android . But , I dont see any rankby distance in api .

Is there any other way to do in Android for AutoComplete Fragment

1

There are 1 answers

0
Ricky Cuarez On BEST ANSWER

Officially, their documentation doesn't support rank by distance feature for Autocomplete. This holds true not only for Places Autocomplete for Android, but to Javascript (client-side) and web service (server-side) as well.

However, a possible workaround would be (depending on your use case), but would be much more expensive, is to make use of Distance Matrix API and create your own Autocomplete depending on its result. So the idea is to:

  1. Use place autocomplete where the default behavior is that for every character, 5 suggested places are given.
  2. Get each of those 5 address's place ID, and do a Distance Matrix request to all of them to get their distance to one another.
  3. Do an event on the textbox and provide those addresses in a dropdown that is sorted by distance. Something like this

You might also want to consider filing a feature request for that functionality to be added on their public issue tracker. Here is a link to guide you for your reference: https://developers.google.com/maps/support