我想比较用户的经纬度,获取距离,并在recyclerview上显示出来。
我认为它会进行一些修改。 请帮帮我。
数据库图片
//show distance
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
reference = FirebaseDatabase.getInstance().getReference("Users");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//set locationA's longitude,latitude
Location locationA = new Location("CurrentUser");
String longitude = dataSnapshot.child(firebaseUser.getUid()).child("long").getValue().toString();
double LongitudeA = Double.parseDouble(longitude);
String latitude = dataSnapshot.child(firebaseUser.getUid()).child("lat").getValue().toString();
double LatitudeA = Double.parseDouble(latitude);
locationA.setLongitude(LongitudeA);
locationA.setLatitude(LatitudeA);
//set locationB's longitude,latitude
Location locationB = new Location("others");
locationB.setLongitude(??????);
locationB.setLatitude(?????);
//show distance
double distance;
distance =locationA.distanceTo(locationB)/100;
int km = (int)distance;
String meter;
meter=Double.toString(km);
holder.distanceView.setText(meter+"km");//recyclerview
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});