Добавить Google Maps как вызовы subview viewDidLoad () бесконечно - PullRequest
0 голосов
/ 10 мая 2019

Я пытаюсь добавить представление Google Maps как подпредставление 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!)
}

xcode callstack

Ответы [ 2 ]

0 голосов
/ 17 мая 2019
 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
}
0 голосов
/ 10 мая 2019

Я создаю 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
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...