How to display something over the google map?

2019-08-05 18:01发布

I am very new to both iOS developing and using the google maps sdk. I am using Xcode for my current project. I have added my API keys in the appropriate place.

So far I have this:

import UIKit
import GoogleMaps
import GooglePlaces

class MyViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func loadView() {
        // Create a GMSCameraPosition that tells the map to display the
        // coordinate -33.86,151.20 at zoom level 6.
        let camera = GMSCameraPosition.cameraWithLatitude(36.2108, longitude: -81.6774, zoom: 17.0)
        let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
        mapView.myLocationEnabled = true
        self.view = mapView
    }

}

When I build and run the app using my phone, the app installs, runs, and displays the google map of the latitude and longitude I asked it to. My question is how do i display something over the map? I want to add a button that says "Start" centered near the top of the screen. But when i go to Main.storyboard and add a button it does not appear (presumably because my map is over it?)

Thanks!

1条回答
唯我独甜
2楼-- · 2019-08-05 18:57

in storyboard views hierarchy make sure the button goes after (below) the map view, also you can code like

self.view.bringSubview(toFront: yourButton)
登录 后发表回答