RockStar RockStar - 3 months ago 45x
iOS Question

Button on the GMSMapView (Google Map) using Swift

As I am new to Swift programming and also iOS development, I am facing problem of placing button on top of Google Map.

I have been using Google Map SDK for iOS using Cocopods, and example from Google Map API guide.

override func viewDidLoad() {

var camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true;
self.view = mapView

var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia" = mapView


I want to place button above the map.

enter image description here


Just create a UIButton and add it to your view after adding the map, as the last thing in your viewDidLoad should be fine.

let button = UIButton(frame: whereYouWant)