Reputation: 31
I have a method that I cdreated called getAssignedCustomerLocation that creates a database reference with the variable name assignedCustomerRef but,that database reference does not actually show up in my firebase console. No node is created on the actual console for it. Code below
public void getAssignedCustomerLocation(){
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child("customerRequest").child(userId).child("l");
assignedCustomerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
List<Object> map = (List<Object>) dataSnapshot.getValue();
double locationLat = 0;
double locationLong =0;
if (map.get(0)!=null) {
locationLat= Double.parseDouble(map.get(0).toString());
}
if (map.get(1)!=null){
locationLong = Double.parseDouble(map.get(1).toString());
}
LatLng driverLatLong = new LatLng(locationLat,locationLong);
mMap.addMarker(new MarkerOptions().position(driverLatLong).title("your driver"));
}
}
Upvotes: 0
Views: 101
Reputation: 933
The code you have used is to read from firebase. If you want to write a new node to the db use below.
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child("customerRequest").child(userId).child("l");
assignedCustomerRef.setValue("YOUR_DATA");
Upvotes: 1
Reputation: 80924
To create a node in the database you need to use setValue()
, so you can do the following:
DatabaseReference assignedCustomerRef = FirebaseDatabase.getInstance().getReference().child("customerRequest").child(userId);
assignedCustomerRef.child("l").setValue("your driver");
Upvotes: 1