我正在尝试在firebase数据库中的特定结构上发布数据,但无法获得预期的结果。需要像以下结构:
ABC->DEVICE_ID-COORDINATES->DATE->PUSHKEY (EX:-KSHJDWFQ)->NOW CHILD LATITUDE AND LONGITUDE.
我无法将孩子推向预期的模式。
预期模式:
{
"ABC" : {
"1_861645036247906" : { ///device id
"co-ordinates" : { ///coordinates
"15-11-2017" : { ///date
"KSHJDWFQ" : { ///push key
"latitude" : 4564564,
"longitude" : 45454545
},
"khgjhkhjk" : {
"latitude" : 456456456,
"longitude" : 435345345
}
},
"16-11-2017" : {
"KSHJDWFQ" : {
"latitude" : 4564564,
"longitude" : 45454545
},
"khgjhkhjk" : {
"latitude" : 456456456,
"longitude" : 435345345
}
}
},
"driver_details" : {
"driver_id" : 1,
"driver_name" : "avik"
}
}
},
}
我的结果是这样的:
{
"ABC" : {
"2_861645036247906" : {
"-Kz8lFh9B86pCj62gcN3" : {
"coordinates" : {
"17-11-2017" : {
"latitude" : "22.5735875",
"longitude" : "88.431699"
}
}
},
"-Kz8ldboHvGS5QabIVZY" : {
"coordinates" : {
"17-11-2017" : {
"latitude" : "22.5735875",
"longitude" : "88.431699"
}
}
}
}
}
}
这是我所做的代码:
Driver driver = new Driver();
String child_node = KPUtils.get_driver_IdPreference(mContext) + "_" + KPUtils.getdeviceid(mContext);
Firebase ref = new Firebase("https://pool------").child(child_node);
String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
Map<String, String> m_coordinates = new HashMap<>();
m_coordinates.put("latitude", st_latitude);
m_coordinates.put("longitude", st_longitude);
Map<String, Map<String, String>> gens = new HashMap<>();
gens.put(date, m_coordinates);
Map<String, String> m_driverdetails = new HashMap<>();
m_driverdetails.put("driver_id", "1");
m_driverdetails.put("driver_name", "Avik");
driver.setCoordinates(gens);
//driver.setDriver_details(m_driverdetails);
ref.push().setValue(driver);
答案 0 :(得分:3)
你可以试试这个......
ref.child("abc")
.child("device id")
.child("coordinates")
.child(date)
.push()
.setValue(m_coordinates);