Search code examples
mkmapviewios11swift4apple-maps

MKMapView doesn't load map and show yellow background


Once I start the app it should load the map of the city you are in. It worked perfectly in IOS 9-10. Since iOS 11 map started to act strangely. Now when you start the app it shows yellow map. If I click home button, wait 3-5 sec and go back into the app, it will show map like it should... Tried to debug it, change layout structure, nothing helped.. Below you can see screenshots when you open the app first time and after 5 seconds of going back to home screen.

Adding to the view like this:

mapView.isScrollEnabled = false
mapView.isZoomEnabled = false
mapView.isPitchEnabled = false
mapView.isRotateEnabled = false
mapContainer.addSubview(mapView)
mapView.fillSuperview()

And then set map once location is detected like this:

let center = CLLocationCoordinate2D(latitude: mapLatitude - 0.004, longitude: mapLongitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.04, longitudeDelta: 0.04))
self.mapView.setRegion(region, animated: true)

Map view on app start enter image description here


Solution

  • So the error was in wrong initialisation. I did initialise mapview on the top of the viewController when I was supposed to do it inside viewDidLoad. That fixed the issue.