我正在使用Google Place API,以获取用户当前位置的位置列表附近。我成功获取了用户当前位置特定半径的列表。我希望此位置列表按距离递增。因此,离我最近的位置应显示在列表顶部。到目前为止,这是我使用Google Place Textsearch API所做的事情。

https://maps.googleapis.com/maps/api/place/textsearch/json?query=real+peprika&key=your_key&location=23.020820000000004,72.57407666666667&radius=50000&rankBy=distance

在这里,我使用了当前位置的纬度和经度。 radius是我要搜索位置的位置。我还使用rankBy = distance按距离顺序获取列表,但无法按升序获取位置。任何帮助将不胜感激。

最佳答案

将适配器设置为listView之后。

Collections.sort(rowItems, new CustomComparator());
adapter.notifyDataSetChanged();

public class CustomComparator implements Comparator<YOUROBJECTCLASSNAME> {
        @Override
        public int compare(YOUROBJECTCLASSNAME o1, YOUROBJECTCLASSNAME o2) {
            return Double.compare(o1.getdistance,o2.getdistance);
        }
    }

关于android - 位置列表升序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30001122/

10-11 22:30
查看更多