Firebase:如何比较数据集

时间:2019-02-11 12:04:52

标签: android firebase firebase-realtime-database location

我想比较用户的经纬度,获取距离,并在recyclerview上显示出来。

我认为它会进行一些修改。 请帮帮我。

数据库图片

enter image description here

//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) {

        }
    });

0 个答案:

没有答案