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
I finally figured out how to display the map in a UIView created in Storyboard and center it in a specific location.
Note: After created the UIView outlet, I changed its class to GMSMapView as explained before.
import UIKit
import GoogleMaps
class ViewController: UIViewController {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var toolBar: UIToolbar!
@IBOutlet weak var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 52.520736, longitude: 13.409423, zoom: 12)
self.mapView.camera = camera
let initialLocation = CLLocationCoordinate2DMake(52.520736, 13.409423)
let marker = GMSMarker(position: initialLocation)
marker.title = "Berlin"
marker.map = mapView
}
And this is the output: Map centred in Berlin