iOS Mapkit in Swift: center on user location when view loads

I have a function for centering a map view on the users current location. I have done all the permissions and stuff got got it working when a button is clicked but not when the app loads.

I want the app to centre on the users location and display the blue dot as soon as the app opens

My function perfectly when called due to a button being clicked but when i put it into the viewDidLoad() function it just doesn't work at all.

Can anyone help me work out why this is.

Both viewDidLoad() and my centerMeClicked() functions call the same centerOnMe() function so i cannot work out why it doesn't work the same for both.

func centerOnMe() {

    let locationManager: CLLocationManager! = CLLocationManager()
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest

    // Check for Location Services
    if (CLLocationManager.locationServicesEnabled()) {

    mapView.showsUserLocation = true
    let userLocation = mapView.userLocation.coordinate

    mapView.setCenter(userLocation, animated: true)

    DispatchQueue.main.async {