Here I am finding out all the sorted list of entity on the basis of it's distance from the current location.
When i put any constant value in place of ebeeRoutePlansList.get(i).getRetailerLatitude() then collection.sort get work well . Is there any problem with my data inside latitude or other things. Here is link of my api http://52.74.125.208:9080/routeplanuser/getUserVisitDetails/1
from where we get latitude and longitude and saved in EbeeRouteplanlist
for(int i = 0; i < ebeeRoutePlansList.size(); i++)
{
double dLat = Math.toRadians(currentLatitute-ebeeRoutePlansList.get(i).getRetailerLatitude());
double dLng = Math.toRadians(currentlongitude-ebeeRoutePlansList.get(i).getRetailerLongitude());
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(28.459267)) * Math.cos(Math.toRadians(currentLatitute)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
dist = (float)(earthRadius * c);
Log.d(TAG,"the distance of each lat Long ==="+dist+"name "+ebeeRoutePlansList.get(i).getRetailerName());
ebeeRoutePlansList.get(i).setShortedDistance(dist);
}
I have used Collections.sort(ebeeRoutePlansList, new DistanceComparator());
the DistanceComparator class having
class DistanceComparator implements Comparator<EbeeRoutePlan> {
@Override
public int compare(EbeeRoutePlan a, EbeeRoutePlan b) {
Log.d(TAG,"the compare method inside Distance Comparator "+a.getShortedDistance()+" --- "+b.getShortedDistance());
if(a.getShortedDistance() == null || b.getShortedDistance() == null)
{
return 0;
}
return a.getShortedDistance() < b.getShortedDistance() ? -1 : a.getShortedDistance() == b.getShortedDistance() ? 0 : 1;
}
}
First this ouput get print
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.542 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.552 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 0.09162273
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.562 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 0.09162273
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 0.09162273 --- 8.636234
12-07 21:37:20.572 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid D/CartPageActivity﹕ the compare method inside Distance Comparator 8.636234 --- 8.636234
then the exception occur after last line get executed
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ java.lang.IllegalArgumentException: Comparison method violates its general contract!
12-07 21:37:20.582 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.TimSort.mergeLo(TimSort.java:743)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.TimSort.mergeAt(TimSort.java:479)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.TimSort.mergeCollapse(TimSort.java:406)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.TimSort.sort(TimSort.java:210)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.TimSort.sort(TimSort.java:169)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.Arrays.sort(Arrays.java:2038)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.util.Collections.sort(Collections.java:1891)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at com.ebee.mobile.nativeandroid.activities.cartpage.CartPageActivity.getSortedDistanceRetailerList(CartPageActivity.java:853)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at com.ebee.mobile.nativeandroid.activities.cartpage.CartPageActivity$1.run(CartPageActivity.java:188)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:725)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:92)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at android.os.Looper.loop(Looper.java:176)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5317)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
12-07 21:37:20.592 25683-25683/com.ebee.mobile.nativeandroid W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
Can you please help me to sort out this problem