저는 현재 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
}
})
고맙습니다!
안녕하세요 Becca, 오류 메시지가 나타 났습니까? 지도에서 실제로 무엇을 볼 수 있습니까? 당신이 생각하는 것을 이해하기위한 다른 세부 정보는 잘못 되었나요? –