将按钮放在谷歌地图视图上

时间:2017-12-03 01:47:52

标签: ios swift google-maps

我想在iOS上的Google Map View上显示一个按钮。我正在使用Xcode并尝试了以下代码:

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()

}

地图加载时我看不到任何按钮。 这就是故事板的样子:

Main Storyboard

以下是约束: enter image description here

如何显示此按钮?

1 个答案:

答案 0 :(得分:1)

如果您在父视图中添加了按钮,则可以管理以下约束:

enter image description here

相反,如果按钮位于父视图的外部和上方,您可以使用:

enter image description here

相关问题