現在、firebaseからデータを取得して、MKMapKitViewで注釈を作成しようとしています。私はデータを正しく取得しているが、注釈を適切に作成していないと考えています。Firebaseから座標を取得して注釈を作成する
私は、複数のユーザーがいるので、注釈の通常の方法として設定することはできません。
let userLocation = CLLocationCoordinate2D(latitude: Double(userLatitude!), longitude: Double(userLongitude!))
let userAnnotation = MKPointAnnotation();
userAnnotation.coordinate = self.userLocation!;
//userAnnotation.title = "Riders Location";
map.addAnnotation(userAnnotation);
}
また、ユーザーを取得する方法も追加します。
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 userLongitude = value["long"] as? Double,
let userLatitude = value["lat"] as? Double
{
userToShow.fullName = value["full name"] as? String
userToShow.imagePath = value["urlToImage"] as? String
userToShow.userID = value["uid"] as? String
userToShow.userLongitude = value["long"] as? String
userToShow.userLatitude = value["lat"] as? String
self.user.append(userToShow)
}
}
}
}
DispatchQueue.main.async {
self.map.reloadInputViews()
//not sure if this is right
}
})
ありがとうございました!
こんにちはベッカ、何かエラーメッセージが表示されますか?あなたのマップには実際に何が表示されますか?私たちがあなたの考えを間違っていると感じる感情を得るためのその他の詳細は? –