【发布时间】:2019-12-01 10:23:35
【问题描述】:
我有一个我创建的名为 getAssignedCustomerLocation 的方法,它使用变量名assignedCustomerRef 创建一个数据库引用,但是该数据库引用实际上并没有显示在我的firebase 控制台中。没有在实际控制台上为其创建节点。代码如下
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"));
}
}
【问题讨论】:
-
你能展示你的数据库结构吗?
-
addValueEventListener 用于从 firebase db 读取,而不是写入。
-
请将您的数据库结构添加为 JSON 文件或至少作为屏幕截图。也请回复@AlexMamo
标签: java android firebase firebase-realtime-database geofire