I want to sort a list of places which are saved in my firebase database with their longitude and latitude i have the current location saved the the variable Latlng i succeded in showing the current lat long and every place's lat long in the logcat but I couldn't find the algorithm that sort these places here is my code
private List<Pharmacie> sortPharmacies(List<Pharmacie> mPhList) {
double currentlong = latLng.longitude;
double currentlat = latLng.latitude;
System.out.println("currentLat: "+currentlat+" ,currentLong: "+currentlong);
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
mPhList.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
Pharmacie pharmacie = snapshot.getValue(Pharmacie.class);
System.out.println(pharmacie);
DataSnapshot dataSnapshot1 = snapshot.child("Location");
;
for (DataSnapshot dataSnapshot2 : dataSnapshot1.getChildren()) {
System.out.println(dataSnapshot2);
// Location location = dataSnapshot2.getValue(Location.class);
}
}
} else {
Toast.makeText(ClosestPharmacy.this, "NO RESULT!", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
return mPhList;
}
here is the Pharmacie table
here is the output of this code
/System.out: currentLat: 36.8747844 ,currentLong: 7.7170403
I/System.out: com.memoire.getmymed.Model.Pharmacie@544210c
I/System.out: DataSnapshot { key = Lat, value = 8.7415141 }
I/System.out: DataSnapshot { key = Long, value = 37.8977585 }
I/System.out: com.memoire.getmymed.Model.Pharmacie@b5bea55
I/System.out: DataSnapshot { key = Lat, value = 7.7469683 }
DataSnapshot { key = Long, value = 36.894459 }
I/System.out: com.memoire.getmymed.Model.Pharmacie@a46dc6a
I/System.out: DataSnapshot { key = Lat, value = 7.7415141 }
I/System.out: DataSnapshot { key = Long, value = 36.8977585 }
I/System.out: com.memoire.getmymed.Model.Pharmacie@b50555b
I/System.out: DataSnapshot { key = Lat, value = 7.7238948 }
I/System.out: DataSnapshot { key = Long, value = 36.895591 }
