Load all firebase data into mapView
You need to get all your events from your Events collection and then loop trough all events and add them.
let db = Firestore.firestore()
db.collection("Events").getDocuments { (snapshot, error) in
if let documents = snapshot?.documents {
for document in documents {
let coordinates = CLLocationCoordinate2D(latitude: (value["latitude"] as! CLLocationDegrees), longitude: value["longitude"] as! CLLocationDegrees)
let event = Event(title: value["title"] as? String, locationName: value["location"] as? String, discipline: value["discipline"] as? String, coordinate: coordinates)
self.mapView.addAnnotation(event)
}
}
}
How to fetch location markers from firebase realtime database and add to map view in Xcode with swift
you can simply replace your old tableView forRowAt func with
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "countCell") as! countCell
let nightClub: NightClubs
nightClub = nightClubs[indexPath.row]
let artwork = Artwork(title: nightClub.name,
locationName: nightClub.location,
discipline: nightClub.type,
coordinate: CLLocationCoordinate2D(latitude: Double(nightClub.latitude)!, longitude: Double(nightClub.longitude)!)
)
mapView.addAnnotation(artwork)
cell.goingCountLabel.text = nightClub.goingCount
cell.liveCountLabel.text = nightClub.liveCount
return cell
}
then remove your hardcoded Artwork objects and its relations
Swift 3 Firebase to MapKit
Using MKPointAnnotation() will only place a pin on the map. You need to use a custom class to hold the annotation information and call it with initializers.
Original:
let annotation = MKPointAnnotation()
annotation.coordinate = pinCoordinate
self.mapContainerView.addAnnotation(annotation)
Working version:
let annotation = PinAnnotation(title: MTA, coordinate: pinCoordinate, info: MTA)
annotation.coordinate = pinCoordinate
self.mapContainerView.addAnnotation(annotation)
Also Need:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
}
and
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
}
Populate Map With Firebase data
Add the following code after print(lat,long)
print(lat,long)
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(lat, long)
annotation.title = "Hello!" // if you need title, add this line
self.mapView.addAnnotation(annotation)
Related Topics
Need Clarification on Anyobject in Swift
How to Find The Top 3 Maximum Values in a Swift Dictionary
Exc_Badinstruction When Computing a Hash Value
Swiftui Conditional View Transitions Are Not Working
Using a Swiftui List Sidebar in a UIsplitviewcontroller
Allocating Ekeventstore Throws Warnings
Generic Vector with Cardinality Type Safety
Swift 4 Base64 String to Data Not Working Due to String Containing "Incomplete" Emoji
Swift Nstimer Dynamically Changing Interval
Swift Displaying The Time or Date Based on Timestamp
Spacing Between Sections in a Form
Advantage of Computed Properties (Gettable Ones Only) VS. Stored Properties
Swift Use 'Is' for Function Type, Compiler Behavior Is Different with Runtime
Why Can't I Get The Index of a Filtered Realm List
Swift- Mkmapkit View Only One City
Uibutton State Changing While Scrolling The Tableview with Multiple Sections - Swift