Reputation: 521
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
}
}
Upvotes: 1
Views: 1842
Reputation: 47
I encountered the same situation and here is how I solved it.
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
Reputation: 1870
Try this. Drag a new view
into your storyboard and place it under your label like the picture.
Then CTRL+drag from the "Map View" to the "View" and shift+click the following options and click "add constraints"
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