How to retrieve 'double' values saved under one key in Firebase?

前端 未结 3 1733
灰色年华
灰色年华 2021-01-17 06:21

I have stored Geofire coordinates in database and now I\'m trying to retrieve them using childEventListener() like this:

    mDatab         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 06:58

    mDatabase.child("geofire").child(key).child("l").addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    double latati = 0, longit = 0;
                    for (DataSnapshot child : dataSnapshot.getChildren()) {
    //                    Log.e("!! All Data ::> ", child.getKey()+" "+child.getValue());
                        if (child.getKey().equalsIgnoreCase("0")) {
                            latati = Double.parseDouble(String.valueOf(child.getValue()));
                        }
                        if (child.getKey().equalsIgnoreCase("1")) {
                            longit = Double.parseDouble(String.valueOf(child.getValue()));
                        }
                    }
                    Log.e("!_@@__Lat Long ::", latati + " " + longit);
                }
    
                @Override
                public void onCancelled(FirebaseError firebaseError) {
                    Log.e("!!__: ", "onCancelled ", firebaseError.toException());
                }
            });
    

提交回复
热议问题