Search code examples
iosswiftgoogle-mapsgoogle-maps-api-3google-maps-sdk-ios

iOS Google Maps API - Views and Labels will not Overlay Over the Map


I have created a Google Map view using the Google Maps SDK for iOS and the map displays fine. Then I added a label on top of the Map. When I run this the label will not show on top of the map. I've tried moving the label to different positions, messing with constraints, but nothing seems to make the label show. I've also tried putting the label in the View instead of it being a child of Map. It still will not show.

Here is the relevant code:

import UIKit
import GoogleMaps

class MapViewController: UIViewController, GMSMapViewDelegate {


    override func viewDidLoad() {
        super.viewDidLoad()
        let camera = GMSCameraPosition.cameraWithLatitude(37.4987309,
            longitude: -77.4700891, zoom: 10)
        let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)

        mapView.delegate = self
        self.view = mapView
    }
}

Here is the storyboard: Here is the storyboard

enter image description here


Solution

  • Try this. Drag a new view

    enter image description here

    into your storyboard and place it under your label like the picture.

    enter image description here

    Then CTRL+drag from the "Map View" to the "View" and shift+click the following options and click "add constraints"

    enter image description here

    This is simply setting the simple autolayout constraints. CTRL+drag the "Map View" into your view controller's class.

    Replace self.view = mapView, with self.theMapView.addSubview(mapView).

    (where theMapView is the "Map View" in the storyboard)

    Now, instead of your actual main view adding the map as a view, you're just creating a subview that does the same, and you have full control of what goes on top of what!