Search code examples
iosswiftgoogle-maps-sdk-ios

how to put a text field on top of google maps iOS


My goal is to put a text field on top of google maps iOS but seems like it doesn't work

enter image description here

When I run the app, the text field doesn't exist on top of Google Maps

enter image description here

The code

import UIKit
import GoogleMaps

class ViewController: UIViewController {

    @IBOutlet var mapView: GMSMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
        mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
        marker.title = "Sydney"
        marker.snippet = "Australia"
        marker.map = mapView

    }

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

}

Solution

  • Here is the super easy solution to do the same with storyboard.

    Add Constraints

    Note : if you have issues to view GIF, please download and separate frame

    enter image description here

    Output

    <code>enter image description here</code>