找到你要的答案

Q:Location list in ascending order

Q:升序排列的位置列表

I am working on google place API for getting near location list of user's current location. I am succeed in getting the list in particular radius of user's current location. I want this list of location in ascending of distance.So location which is near to me should be display on top of list. Here is what I have done till now with the use of 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

Here I have used latitude and longitude of my current location. radius is in which I want to search location.And I have also used rankBy=distance for getting list in order of distance but I can not get location in ascending order. Any help will be appreciated.

我正在工作的谷歌地方API获得接近位置列表用户的当前位置。我成功地获得列表,特别是用户当前位置的半径。我想在距离上升的地方列出这个列表,所以靠近我的位置应该显示在列表的顶部。这是我做了什么,直到现在谷歌的地方文章搜索API的使用。

https://maps.googleapis.com/maps/api/place/textsearch/json?查询=房+ peprika &;关键= your_key &;位置= 23.020820000000004,72.57407666666667 &;半径= 50000 &;rankby =距离

这里我用了我当前位置的经纬度。半径是我要搜索的位置。我也用rankby =距离为距离获取列表但我不能按升序排列得到的位置。任何帮助将不胜感激。

answer1: 回答1:

After setting adapter to 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);
        }
    }   

在设置适配器列表。

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);
        }
    }   
answer2: 回答2:

please reduce radius to 500. your problem will be solved.

请将半径缩小到500。你的问题将得到解决。

android  search  text  location