wacki wacki - 6 months ago 641
Android Question

How to retrieve data in FIREBASE realtime database based on Latlng

i'm developing android application base on Maps and using firebase database(google real time database free version) too.
but i can't retrieve data using latlng datas.

goals.


  1. How to designs 'key and values'

  2. How to retrieve data. using latlng.



( ex, -34.512 < myPositionLat < 14.235 && 24.352 < myPsitionLng < 64.234 )

help me lovers

Answer

You can Design as following in Firebase Database

- maps
   -locations
     -U123456789
        -lat : 25.265
        -long : 25.32
     -U12345678910
        -lat : 25.265
        -long : 25.32
     -U1234567811
        -lat : 25.265
        -long : 25.32

You can retreive the data as by id suppose U123456789

DatabaseReference mapsrefrence=FirebaseDatabase.getInstance().getReference().child("maps").child("locations");
  mapsrefrence.child("U123456789").addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        if(dataSnapshot.hasChildren()) {
                            @SuppressWarnings("unchecked")
                            Map<String, String> value = (Map<String, String>) dataSnapshot.getValue();

                        } 
                    }
                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.w(TAG, "getUser:onCancelled", databaseError.toException());
                    }
                });
Comments