我有一组经纬度坐标,我想将其保存到 firebase。我知道有 a normal我可以使用的方式。但我想知道如何保存整个阵列。
我想保存的数组如下所示:
(1.323, 2.334),(6.323, 7.334),(0.323, 65.334),(43.323, 32.334)...
我正在使用实时数据库。
最佳答案
let databaseRef = Database.database().reference()
let coordinatesRef = databaseRef.child("path/to/coordinates")
func save(coordinates: [(Double, Double)], completion: @escaping (Error?) -> ()) {
coordinatesRef.setValue(coordinates.map { [$0, $1] }) { completion($0) }
}
save(coordinates: [
(1.323, 2.334),
(6.323, 7.334),
(0.323, 65.334),
(43.323, 32.334)
]) { error in
if let error = error {
print("❌ Saving coordinates to Firebase failed", error)
} else {
print("🔥 Saving coordinates to Firebase succeeded")
}
}
关于ios - 是否可以将坐标数组保存到 firebase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54609201/