Search code examples
iosswiftgoogle-maps-sdk-ios

how to position myLocationButton google maps IOS


Currently, myLocationButton is buried behind a button, if you take a look at the button the myLocationButton is behind that button. How do I move the Y position of the myLocationButton?

enter image description here


Solution

  • Use GMSMapView's padding to make this happen.

    self.mapView.padding = UIEdgeInsetsMake(0, 0, 100, 0)
    

    Replace '100' with whatever space you want the location-button to be pushed up. You should probably replace it with the y-location of your book-button. For example:

    let botPadding = self.view.frame.size.height - self.bookButton.frame.origin.y
    self.mapView.padding = UIEdgeInsetsMake(0, 0, botPadding, 0)
    

    You can probably put this code wherever you want, maybe it'll work in viewDidLoad. But keep in mind that you'll have to call it again if your book-button is supposed to disappear at some point. To make it dynamically placed, you could override viewDidLayoutSubviews or similar.