swift - swift 将 map 图钉从 firebase 加载到 mapkit 上,以便所有用户都能看到

标签 swift firebase firebase-realtime-database mapkit mapkitannotation

我正在创建一个标记应用程序,用户可以在其中将街头艺术标记到 map 上,然后所有用户都可以看到此信息。

我可以将我的数据上传到 Firebase,但是我很难将这些数据拉回以作为注释显示在 map 上。

Firebase Data Structure

我已经创建了一个 loadCustomAnnotations() 来加载数据库信息作为我 map 上的图钉,我知道我需要观察值并只加载到“艺术”路径中,并循环遍历所有结果但是我不能似乎把它变成了注释!谁能帮忙?!谢谢。

func loadCustomLocations() {

    FIRDatabase.database().reference(withPath: "art")

    let artPin = FIRDatabase.database().reference(withPath: "art")

    artPin.observe(.value, with: { snapshot in


        for item in snapshot.children {
            guard let snapshot = item as? FIRDataSnapshot else { continue }

            let ref = art(snapshot: snapshot)

            print(snapshot)

            self.artDrops.append(ref)

     //       self.makeAnnotation(artDrops: art)


        }
    })
}

这个函数现在打印我所有的位置,我只需要知道如何将它变成一个注释!

Printing Locations

最佳答案

只要您现在能够上传并取回所有位置,接下来的步骤就不会那么难了。只需使用 .addAnnotations 就可以了!

let artAnnotation = MKPointAnnotation()
            var artDrops = [CLLocation]()
            for location in artDrops{
            artAnnotation.coordinate = location.coordinate
            artAnnotation.title = "your location title"
            mapView.addAnnotations([artAnnotation])
            }

关于swift - swift 将 map 图钉从 firebase 加载到 mapkit 上,以便所有用户都能看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44354730/

相关文章:

swift - 如何将UISlider的滑动限制在某个点?

ios - Firestore 不返回查询 Swift 5 Xcode 11.3

android - Firebase ML 套件给出 FirebaseMLException : Waiting for the text recognition model to be downloaded. 请稍候

firebase - 如何更新 firebase 数据库中具有随机生成的 ID/KEY 的值

ios - Swift 3 将 Firebase 数据写入 TableView

java - 无法检索子项下的所有计数

swift - UITableView - 根据 UITableView 的行号在主视图 Controller 中执行不同的功能

swift - 如何在 Swift 中读取结构的字节

ios - 为什么我的应用在 iPhone 12 mini 上显示的尺寸不正确?

ios - 为什么我的 firebase 数据库不等待更新值