How put Google MapView in UIView?

后端 未结 2 387
鱼传尺愫
鱼传尺愫 2021-01-18 00:06

I\'m trying to put Google MapView in UIView but I get nothing displayed.

My code,

*.h

#import 
#import <         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 00:32

    Essentially in the storyboard, for the corresponding View(UIVIew) you're going to show the Google Map, you have to set the class as GMSMapView in identity inspector.

    This is how view controller would look like in Swift 3.

    class GMapsViewController: UIViewController {
        @IBOutlet weak var mapContainerView: GMSMapView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
    
           let marker = GMSMarker()
           marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
           marker.title = "Sydney"
           marker.map = mapContainerView
    
           mapContainerView.moveCamera(GMSCameraUpdate.setCamera(camera))
    
    
           }
    }
    

提交回复
热议问题