如何从数据库中完全删除密钥
How do I remove a key completely from Database
我想从 geoFire 中完全移除一辆车,但是当我 运行 这样做时:
@Override
public void onKeyExited(String key) {
// Remove any old marker
Marker marker = this.markers.get(key);
if (marker != null) {
marker.remove();
this.markers.remove(key);
}
}
它已从当前视图中删除,但当我刷新位置时,车辆就在那里。
您当前的代码只是从应用程序中删除标记,不会从数据库中删除任何数据。要删除车辆,您需要执行与添加车辆时相反的操作。
来自GeoFire for Java documentation on setting location data:
To set a location for a key simply call the setLocation()
method. The method is passed a key as a string and the location as a GeoLocation
object containing the location's latitude and longitude:
geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973));
To remove a location and delete it from the database simply pass the location's key to removeLocation:
geoFire.removeLocation("firebase-hq");
我想从 geoFire 中完全移除一辆车,但是当我 运行 这样做时:
@Override
public void onKeyExited(String key) {
// Remove any old marker
Marker marker = this.markers.get(key);
if (marker != null) {
marker.remove();
this.markers.remove(key);
}
}
它已从当前视图中删除,但当我刷新位置时,车辆就在那里。
您当前的代码只是从应用程序中删除标记,不会从数据库中删除任何数据。要删除车辆,您需要执行与添加车辆时相反的操作。
来自GeoFire for Java documentation on setting location data:
To set a location for a key simply call the
setLocation()
method. The method is passed a key as a string and the location as aGeoLocation
object containing the location's latitude and longitude:
geoFire.setLocation("firebase-hq", new GeoLocation(37.7853889, -122.4056973));
To remove a location and delete it from the database simply pass the location's key to removeLocation:
geoFire.removeLocation("firebase-hq");