ParseのAndroid Documentationによると、別のソート順を自分で指定しない限り、既定の並べ替え順序は既に距離(最も近いもの)であるはずです。他のすべてが失敗し、ソート順だけでない場合
また、あなたはなど、あなただけのキロメートル、マイル、一定数の内の場所をしたい
を指定することができるようParseQuery.whereWithin*
メソッドに見たいと思うかもしれません返された場所で作業したい場合は、クエリから返されたParseObject
をループし、ParseObject.getParseGeoPoint("rest_location")
を使用して、自分で並べ替えることができます。 ParseGeoPoint
オブジェクトを返します、あなたは、ユーザーの場所までの距離を取得し、その上でソートするには、次の
ParseGeoPoint.distanceInKilometersTo(sLatlong);
を行うことができます
。ここでは参考のため
は、サンプルComparator
です:あなたが持っている
public class UserLocationComparator implements Comparator<ParseObject> {
private final ParseGeoPoint userLoc;
public UserLocationComparator(ParseGeoPoint userLoc) {
this.userLoc = userLoc;
}
@Override
public int compare(ParseObject po1, ParseObject po2) {
ParseGeoPoint loc1 = po1.getParseGeoPoint("rest_location");
ParseGeoPoint loc2 = po2.getParseGeoPoint("rest_location");
return loc1 == null ?
(loc2 == null ? 0 : 1) :
(loc2 == null ? -1 : Double.compare(userLoc.distanceInKilometersTo(loc1), userLoc.distanceInKilometersTo(loc2)));
}
}
、その後仮定List<ParseObject> results;
単に実行します。
Collections.sort(results, new UserLocationComparator(sLatlong));
あなたはParseが正しくシャットダウンしていることを知っていますか? 2017年1月にサービスが停止されます。 http://blog.parse.com/announcements/moving-on/ – Dom
ええ、私はそれを知っています。私はこれを3ヶ月間使って、私のアイデアを検証します。 – Anirudh
結果が並べ替えられていないと答えたときの副次的注意は、 'FindCallback.done(...)'メソッドで結果の順序をチェックしているかどうかです。それ以外の場合は、結果の順序をチェックしていますか?結果を処理した後にあなた自身が注文を変更している可能性があります。 –