So for my mapView, I am receiving coordinates from another VC by passing it longitude and latitude through a global array like such:
Adding the latitude and longitude into the array:
var location_one: [String: Any] = ["title": eventName, "latitude": latitude, "longitude": longitude]
locations.append(location_one)
if let tbc = self.tabBarReference {
if let map = tbc.viewControllers?[1] as? MapVC {
map.loadViewIfNeeded()
map.add(newLocation:location_one)
}
}
Receiving the coordinates on the MapViewVC:
func add(newLocation location_one:[String:Any]) {
let momentaryLat = (location_one["latitude"] as! NSString).doubleValue
let momentaryLong = (location_one["longitude"] as! NSString).doubleValue
let annotation = MKPointAnnotation()
annotation.title = location_one["title"] as? String
annotation.coordinate = CLLocationCoordinate2D(latitude: momentaryLat as CLLocationDegrees, longitude: momentaryLong as CLLocationDegrees)
map.addAnnotation(annotation)
// self.map.centerCoordinate = annotation.coordinate
}
viewForannotation code:
func mapView(_ map: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "pinAnnotation"
var annotationView = map.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
}
annotationView?.annotation = annotation
return annotationView
}
The coordinates are properly transferring and the func add is being called upon (verified using a break statement), however when I go to the MapView in the simulator, the annotation isn't being placed. I have no idea what is going on, as this worked properly in another App I tested, but don't have a clue what could cause it to mess up.
I also have code that finds the user's current location and places a pin based on that... perhaps that could mess up the add coordinate code?