如何将函数中的注释添加到我的地图?

问题描述

我需要从 Cloud Firestore 向我的地图添加注释... 在 Cloud Firestore 中,我的注释以这种方式存储: 带有“纬度”和“经度”字段的“文档 ID”... 所以我用这个函数得到它们:

func getAnnotations() {

    FirestoreReferenceManager.referenceForAnnotations().addSnapshotListener { (querySnapshot,err) in
        
        guard (querySnapshot?.documents) != nil
            else {
                print("No documents")
                return
            }
        
        for document in querySnapshot!.documents {

            let lat = document.get("latitude") as! String
            let lon = document.get("longitude") as! String
                        
            let latitude =  Double(lat)
            let longitude = Double(lon)
            let truecoordinate : CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: latitude ?? 0,longitude: longitude ?? 0)
            let annotation = MKPointAnnotation()
            annotation.coordinate = truecoordinate
        }
    }
}

地图本身在另一个文件中声明:

struct MapView: View {
@State private var region = MKCoordinateRegion(
        center: CLLocationCoordinate2D(latitude: 55.791,longitude: 37.711617),span: MKCoordinateSpan(latitudeDelta: 0.02,longitudeDelta: 0.02)
    )
var body: some View {
    Map(coordinateRegion: $region)
        .ignoresSafeArea()
}
}

所以我的问题是:如何制作从 DataBase (Cloud Firestore) 获取的注释数组并将它们添加到我在 SwiftUI 中的另一个文件中声明的地图中?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...