我正在尝试从 Firebase 中提取我的地图显示地点,该地点距离我的用户半英里范围内,但是我还没有到那里。有人可以帮忙吗?
这就是我现在正在做的事情:
1) 在我的 viewDidLoad 中使用我的 Firebase 数据库中的数据填充地图和 tableView:
var posts = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
// Set up Map
mapView.delegate = self
mapView.userTrackingMode = MKUserTrackingMode.follow
// Setup TableView
tableView.delegate = self
tableView.dataSource = self
//Pulls TableData for UITableView
DataService.ds.REF_VENUE.observe(.value, with: { (snapshot) in
self.posts = [] // THIS IS THE NEW LINE
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
for snap in snapshot {
if let postDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let post = Post(postKey: key, postData: postDict)
self.posts.append(post)
}
//Populates Map with annotations.
if let locationDict = snap.value as? Dictionary<String, AnyObject> {
let lat = locationDict["LATITUDE"] as! CLLocationDegrees
let long = locationDict["LONGITUDE"] as! CLLocationDegrees
let title = locationDict["NAME"] as! String
let center = CLLocationCoordinate2D(latitude: lat, longitude: long)
_ = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.20, longitudeDelta: 0.20))
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(lat, long)
annotation.title = title.capitalized
self.mapView.addAnnotation(annotation)
}
}
}
self.tableView.reloadData()
})
}
2)然后我的tableView设置正常:posts[indexPath.row],从专门为其定制的类中提取。
但是,回到问题上来,所有位置都出现了。地图上的所有场地都人满为患。谁能帮忙!!!