如何将push()添加到路标子项?无法正确处理..
Map mWaypoints = new HashMap();
mWaypoints.put("latitude", mCurrentLatlngOnCreate.latitude);
mWaypoints.put("longitude", mCurrentLatlngOnCreate.longitude);
Map mParent = new HashMap();
mParent.put("routeID", "my route id");
mParent.put("routeName", "my route name");
mParent.put("Waypoints", mWaypoints);
myFirebaseRef.push().setValue(mParent);
这是当前结果,但希望在Waypoints下使用推入ID。
-KGNWnjgXPC0kHYiOKG7
Waypoints // <--- Want to get the unique below here
latitude: 31
longitude: 421
routeID: "my route id"
routeName: "my route name"
最佳答案
push()
是纯客户端操作,可以单独调用。所以:
Map mWaypoints = new HashMap();
mWaypoints.put("latitude", mCurrentLatlngOnCreate.latitude);
mWaypoints.put("longitude", mCurrentLatlngOnCreate.longitude);
String key = myFirebaseRef.push().getKey();
Map mWayPointsMap = new HashMap();
mWayPointsMap.put(key, mWayPoints);
Map mParent = new HashMap();
mParent.put("routeID", "my route id");
mParent.put("routeName", "my route name");
mParent.put("Waypoints", mWayPointsMap);
myFirebaseRef.push().setValue(mParent);