我使用 longtapgesture 识别器添加地点,虽然它显示在我的地图上,但当我离开视图然后返回时它消失了。
所以我使用firebase来添加位置来获取位置,我希望它显示在我的地图视图上。我正在获取 snapshot.value 的值,我正试图在我的 mapview 上展示,请帮助我。这是我似乎无法弄清楚的最后一步。
func fetchlocations() {
let ref = Database.database().reference()
ref.child("Map").observe(.value) { (snapshot) in
print(snapshot.value)
let activity = (snapshot.value as AnyObject!)!["activity"] as? String?
let lat = (snapshot.value as AnyObject!)!["lat"] as? String?
let long = (snapshot.value as AnyObject!)!["long"] as? String?
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: (Double(lat!))!, longitude: (Double(long!))!)
annotation.title = activity
self.mapView?.addAnnotation(annotation)
}
}