Houssem TRABELSI
Houssem TRABELSI

Reputation: 842

Firebase timestamp as a custom key

can some one help me ,how can i getting timestamp key from firebase to put them on Map<String, Marker> markers = new HashMap(); as keys here is my schema

enter image description here

Upvotes: 0

Views: 335

Answers (1)

Gast&#243;n Saill&#233;n
Gast&#243;n Saill&#233;n

Reputation: 13129

This should be your approach to solve this problem

 // Attach a listener to read the data at our database 
    mDatabase.child("hopitaux").addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot snapshot : dataSnapshot.getChildren())
         {
             //this will get all the timeStamps keys of your database
            long timestamps = snapshot.getKey();

            //if you want to get all the values inside each key you should make a Bean with the data that you want to request, i understand that Marker.class is your object with all your getters so 
              Marker mark = snapshot.getValue(Marker.class);
              Map<String, Marker> markers = new HashMap();
              markers.put("lat",mark.getLat());
              markers.put("lng",mark.getLng()); //and so on..

           }

      }

      @Override
      public void onCancelled(DatabaseError databaseError) {
        System.out.println("The read failed: " + databaseError.getCode());
      }
    });

Upvotes: 1

Related Questions