问题描述
我需要从 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 (将#修改为@)