I'm trying to have my map display venues, pulled from Firebase, that are within a half mile radius from my user but, I'm not quite there yet. Could anyone assist?
This is what I'm doing now:
1) Populate the map and tableView with the data from my Firebase Database in my viewDidLoad:
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) Then my tableView is set up normally: posts[indexPath.row], pulling from class that was specifically tailored for it.
But, back to the problem, all locations show up. The map is overpopulated with all venues. Could anyone help!!!