2017-11-08 7 views
0

私はfirebaseにアップロードした縦横の度合いから地図に注釈を付けるのに問題があります。すべてのユーザーに注釈を追加したいが、別の関数でuserLatitudeとuserLongitude変数をxcodeに認識させることはできない。Firebaseの座標を注釈として表すSwift

何かが役立ちます!

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" 





    } 

答えて

0

そして、あなたはas? Stringによってas? CLLocationDegreesを変更し、その後CLLocationDegreesでキャストを管理する場合は?

Firebaseでは、データはDouble型ではなくString型で格納されていると思います(CLLocationDegrees型が参照するデータ型)。

+0

文字列をダブルに変更する形式は何ですか?私は今これで問題を抱えています。 –

+0

通常は、単純なDouble(経度)とDouble(緯度)を使用する必要があります。 – schtipoun

関連する問題