StackUser
StackUser

Reputation: 145

Place button over google map view

I am trying to display a button on top of my Google Map View on iOS. I am using Xcode and have tried the following code:

let mapView = GMSMapView() 

 override func loadView(){
    view = mapView

    do{
        if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json"){
            mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
        }
    } catch {
    }

    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: 45.45, longitude: -73.6)
    marker.title = "Montreal"
    marker.snippet = "Canada"
    marker.map = mapView

    onMapReady()

}

I do not see any button when the map loads. This is what the storyboard looks like:

Main Storyboard

Here are the constraints: enter image description here

How would I get this button to appear?

Upvotes: 2

Views: 2054

Answers (2)

novice
novice

Reputation: 451

parentView.bringSubviewToFront(childView)

Upvotes: 0

mugx
mugx

Reputation: 10105

In case you have added your button inside the Parent View you can manage the constraints like:

enter image description here

Instead, if the button is outside and above your Parent View you can use this:

enter image description here

Upvotes: 1

Related Questions