【发布时间】:2017-11-09 03:44:52
【问题描述】:
我目前正在尝试从 firebase 获取我的数据并在我的 MKMapKitView 中创建注释。我相信我正在正确检索数据,但没有正确创建注释。
我认为,因为有多个用户,我不能将其设置为常规的注释方式。
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,您收到任何错误消息吗?你在地图上实际看到了什么?还有什么其他细节可以让我们了解您认为哪里出了问题?
标签: swift firebase annotations mapkit core-location