我无法将上传到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类型所指的数据类型)。

10-08 07:45