Cannot put a google maps GMSMapView in a subview of main main view?

后端 未结 10 1012
遇见更好的自我
遇见更好的自我 2020-11-28 06:50

I\'m struggling with this problem! I want to add a google maps GMSMapView into a UIView that is only a portion of the main UIView of m

10条回答
  •  迷失自我
    2020-11-28 07:24

    Following the google tutorial for Swift in Sep-2017

    I fixed by putting the code in viewDidLoad like this

    var mapView: GMSMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Create a GMSCameraPosition to display the initial center of the map
        let camera = GMSCameraPosition.camera(withLatitude: 23.885942, longitude: 45.079162, zoom: 5.1)
    
        // Set the frame size , don't forget to replace "" with the required frame size
        mapView = GMSMapView.map(withFrame: "", camera: camera)
    
        // Add the map to any view here 
        view.addSubview(mapView)  //or customView.addSubview(mapView)
    }
    

提交回复
热议问题