【发布时间】:2016-10-11 14:45:47
【问题描述】:
我正在使用 Firebase 在 mapView 上获取注释。这是通过以下方式完成的:
func getMarkers() {
dbRef.observe(.value, with: { (snapshot) in
for buildings in snapshot.children {
let buildingsObject = Buildings (snapshot: buildings as! FIRDataSnapshot)
let latDouble = Double(buildingsObject.latitude!)
let lonDouble = Double(buildingsObject.longitude!)
self.telephoneNumber = buildingsObject.number
let annotation = myAnnotationView.init(title: buildingsObject.content!, coordinate: CLLocationCoordinate2D.init(latitude: latDouble!, longitude: lonDouble!), duration: buildingsObject.duration!, cost: buildingsObject.cost!, info: "", timestamp: buildingsObject.timestamp, contactNumber: buildingsObject.number!, addedBy: buildingsObject.addedByUser!)
self.mapView.addAnnotation(annotation)
print (snapshot)
}})}
myAnnotationView 是我的 AnnotationView 自定义类。
向地图添加注释没问题。问题出现在如果用户需要删除他的注释,则需要将其从 mapView 中删除。我有一个包含所有用户注释的表格,如果他们愿意,他可以在其中删除。这会更新到 firebase 控制台并删除数据。但是,注释仍在地图上,只有当您重置应用时,注释才会更新。
我有一种方法可以观察已删除的Childs,我得到了正确的快照,但我似乎无法引用需要删除的注释。
func removeMarkers() {
dbRef.observe(.childRemoved, with: { (snapshot) in
print (snapshot)
})}
被吐出的快照在这里:
Snap (-KTo3kdGGA_-rfUhHVnK) { //childByAutoID
addedByUser = TzDyIOXukcVYFr8HEBC5Y9KeOyJ2;
content = "Post";
cost = 500;
duration = Monthly;
latitude = "25.0879112000924";
longitude = "55.1467777484226";
number = 1234567890;
timestamp = "Tue 11 Oct";
}
所以我的问题是如何删除此快照中的注释?我可以以某种方式引用它的坐标和 removeAnnotation 吗?我查看了 Stack,但它主要提到了如何删除所有注释。
非常感谢。 D
【问题讨论】:
标签: ios swift firebase mapkit firebase-realtime-database