Google Maps GMSMapView on custom UIView

后端 未结 8 1683
陌清茗
陌清茗 2020-12-14 20:33

I want to display google maps on a view that\'s then added to self.view, rather than drawing the map directly on self.view. Therefore, I created a

8条回答
  •  孤城傲影
    2020-12-14 20:50

    Those answers didn't work for me as I wanted. As an improvement for @Rajan's answer, I thought of adding an UIView to storyboard View Controller with desired constraints. Then I added another UIView inside that as child and then I changed class name to GMSMapView. After that I made an Outlet to UIViewController.

    @IBOutlet weak var GMSMap: GMSMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let mapView = GMSMapView.map(withFrame: GMSMap.frame, camera: GMSCameraPosition.camera(withLatitude: 6.9271, longitude: 79.8612, zoom: 10))
        let marker = GMSMarker()
    
        marker.position = CLLocationCoordinate2D(latitude: 6.9271, longitude: 79.8612)
        marker.title = "Colombo"
        marker.snippet = "Sri Lanka"
        marker.map = mapView
        self.view.addSubview(mapView)
    
    }
    

提交回复
热议问题