【问题标题】:Is it possible to save an array of coordinates to firebase?是否可以将一组坐标保存到firebase?
【发布时间】:2019-02-09 18:17:36
【问题描述】:

我有一组经纬度坐标,我想将它们保存到 firebase。我知道我可以使用a normal 方式。但我想知道如何保存整个数组。

我要保存的数组如下所示:

(1.323, 2.334),(6.323, 7.334),(0.323, 65.334),(43.323, 32.334)...

我正在使用实时数据库。

【问题讨论】:

  • 实时数据库?
  • 是的@Callam 是正确的

标签: ios arrays swift firebase


【解决方案1】:
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")
    }
}

【讨论】:

    猜你喜欢
    • 2020-05-24
    • 1970-01-01
    • 2021-04-15
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    相关资源
    最近更新 更多