在 AutoCompleteSupportFragment 中根据距离对搜索结果进行排序

Places Search results to sort based on distance in AutoCompleteSupportFragment

我正在检查此 link 中所述的类似结果,它用于服务器端 Google Places Api sort by distance

我需要根据最近的手机距离对地点进行排序 android。 但是,我在 api 中没有看到任何 rankby distance .

在 Android 中是否还有其他方法可用于自动完成片段

正式地,他们的 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) 也是。

然而,一个可能的解决方法是(取决于您的用例),但会更加昂贵,即利用 Distance Matrix API 并根据其结果创建您自己的自动完成。所以想法是:

  1. 使用位置自动完成,默认行为是为每个字符提供 5 个建议位置。
  2. 获取这 5 个地址中每一个的位置 ID,并对所有地址执行距离矩阵请求,以获取彼此之间的距离。
  3. 在文本框上执行一个事件,并在按距离排序的下拉列表中提供这些地址。类似于 this

您可能还想考虑提交一个功能请求,以便在他们的 public issue tracker. Here is a link to guide you for your reference: https://developers.google.com/maps/support

上添加该功能