user1625155
user1625155

Reputation: 521

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

Upvotes: 1

Views: 1842

Answers (2)

Hokie2014
Hokie2014

Reputation: 47

I encountered the same situation and here is how I solved it.

  • In your storyboard you have a view named 'Map'
  • You created the following camera :

    let camera = GMSCameraPosition.cameraWithLatitude(37.4987309,
    longitude: -77.4700891, zoom: 10)
    
  • Control drag the 'Map' View onto your view controller and name it whatever, such as mapView

  • self.mapView.camera = camera self.mapView.bringSubview(toFront: yourLabelToBePlacedOnTop)

Upvotes: 0

Hayden
Hayden

Reputation: 1870

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!

Upvotes: 2

Related Questions