添加 Google 个地图作为子视图无限调用 viewDidLoad()

Add Google Maps as subview calls viewDidLoad() infinitely

我正在尝试将 Google 地图视图添加为 UIViewController 的子视图。但它给出了一个无限循环调用 viewDidLoad()。如何解决这个问题?

override func viewDidLoad() {
    super.viewDidLoad()
    let camera = GMSCameraPosition.camera(withLatitude: 53.9, longitude: 27.5667, zoom: 6)
    mapView = GMSMapView.map(withFrame: CGRect(x: 100, y: 100, width: 200, height: 200), camera: camera)
    mapView?.center = self.view.center
    self.view.addSubview(mapView!)
}

我正在以编程方式创建 UIViewController 并添加以下代码解决了这个问题。

override func loadView() {
    let screenSize = UIScreen.main.bounds
    view = UIView(frame: CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height))
    view.backgroundColor = UIColor.white
}
 override func loadView() {
//Call the map
let camera = GMSCameraPosition.camera(withLatitude: "your latitude", longitude: "longitute", zoom: 15.0)
mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
self.view = mapView
 mapView.settings.myLocationButton = true // enable current location button on map 
    mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    mapView.isMyLocationEnabled = true
}