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
Very Simple. Use Following Steps
1) Open Storyboard: Drop a UIView from Object library in your ViewController.
2) Make custom view outlet in your class. (viewForGMap in my code)
3) Add following line for code in your class.
class GMapVC: UIViewController {
@IBOutlet weak var viewForGMap: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let camera = GMSCameraPosition.camera(withLatitude: 28.7041, longitude: 77.1025, zoom: 10.0)
let mapView = GMSMapView.map(withFrame: self.viewForGMap.frame, camera: camera)
self.view.addSubview(mapView)
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: 28.7041, longitude: 77.1025)
marker.title = "Delhi"
marker.snippet = "India’s capital"
marker.map = mapView
}
OutPut: