将来自 Firebase 的坐标表示为注释 Swift

Representing Coordinates from Firebase as Annotations Swift

我无法根据上传到 firebase 的经度和纬度在我的地图上添加注释。我想为我的所有用户添加注释,但无法让 xcode 在另一个函数中识别我的 userLatitude 和 userLongitude 变量。

任何事情都会有所帮助!

    func retrieveUsers(){
        let ref = Database.database().reference()
        ref.child("users").queryOrderedByKey().observeSingleEvent(of: .value, with: { snapshot in
            let users = snapshot.value as! [String: AnyObject]
            self.user.removeAll()
            for (_,value) in users {
                if let uid = value["uid"] as? String {
                    if uid != Auth.auth().currentUser!.uid {
                        let userToShow = User()
                        if let fullName = value["full name"] as? String,
                        let imagePath = value["urlToImage"] as? String,
                        //String(format: "%f", self.currentUserLocation?.longitude ?? 0),
                        let userLongitude = value["long"] as? CLLocationDegrees,
                        let userLatitude = value["lat"] as? CLLocationDegrees
                        //why isnt it recognizing the users degrees

                        {
                            userToShow.fullName = value["full name"] as? String
                            userToShow.imagePath = value["urlToImage"] as? String
                            userToShow.userID = value["uid"] as? String
                            userToShow.userLongitude = value["long"] as? CLLocationDegrees
                            userToShow.userLatitude = value["lat"] as? CLLocationDegrees

                            self.user.append(userToShow)
                        }


                    }

                }
            }
            DispatchQueue.main.async {
                self.map.reloadInputViews()

                //not sure if this is right
            }
        })

    }




    func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {

        let otherUserLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(userLatitude, userLongitude)

        let userAnnotation = MKPointAnnotation()
        userAnnotation.coordinate = otherUserLocation
        userAnnotation.title = "fullName"





    }

如果您将 as? CLLocationDegrees 更改为 as? String,然后在 CLLocationDegrees 中管理演员表?

因为我认为,在 Firebase 中,数据存储为 String 而不是 Double(这是 CLLocationDegrees 类型所指的数据类型)。