我正在尝试传递我从Firebase数据库中读取的变量。
func annotatemyMap() {
let refx = Database.database().reference().child("child").child("child").child("child").child("LocX")
ref.observeSingleEvent(of: .value, with: { (snapshot) in
let locX = snapshot.value as! Double
})
let refy = Database.database().reference().child("child").child("child").child("child").child("LocY")
refy.observeSingleEvent(of: .value, with: { (snapshot) in
let LocY = snapshot.value as! Double
})
point.coordinate = CLLocationCoordinate2DMake(locX , locY)
//REST OF MY FUNCTIONS CODE........
}
point.coordinate中的locX和locY为零。我理解为什么,但我无法弄清楚如何将locX和locY传递给point.coordinate。
问题:如何将loxX和locY的值(从firebase读取)传递给point.coordinate。
答案 0 :(得分:1)
您可以尝试嵌套调用或使用完成
let refx = Database.database().reference().child("child").child("child").child("child").child("LocX")
ref.observeSingleEvent(of: .value, with: { (snapshot) in
let locX = snapshot.value as! Double
let refy = Database.database().reference().child("child").child("child").child("child").child("LocY")
refy.observeSingleEvent(of: .value, with: { (snapshot) in
let LocY = snapshot.value as! Double
point.coordinate = CLLocationCoordinate2DMake(locX , locY)
//REST OF MY FUNCTIONS CODE........
})
})