每次我的位置更改时,我都希望它向相同的根ID添加一个航路点,但是每次它仅覆盖根内部的航路点时。已将.setValue更改为.updateChildren,但仍然没有运气。
Firebase mainRef = null;
private void saveToFirebase() {
while (isFirstTime) {
// Generates root id
mainRef = myFirebaseRef.push();
isFirstTime = false;
}
// Generates new id for waypoint
Firebase wayRef1 = mainRef.push();
String waypointKey = wayRef1.getKey();
// Create waypoint post
Map<String, Object> newPost = new HashMap<String, Object>();
newPost.put("latitude", mLastLocation.getLatitude());
newPost.put("longitude", mLastLocation.getLongitude());
// POST HOLDER
Map<String, Object> waypointHolder = new HashMap<>();
waypointHolder.put(waypointKey, newPost);
// PARENT OF WAYPOINTHOLDER
Map mParent = new HashMap();
mParent.put("timeStamp", mLastUpdateTime);
mParent.put("waypoints", waypointHolder);
mainRef.updateChildren(mParent);
}
看起来您正在创建航点值的哈希图,但是在添加新值之前,不要将现有值加载到哈希图中。因此,您每次都会创建一个新的哈希图,向其中添加一个条目,然后将其发布到firebase。这将导致每次存储在Firebase中的哈希图只有一个航点条目。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句