2

I am new in swift and making an app in which I am using Gogle Map SDK for iOS. I have used myLocationButton and it is initially set up on the right bottom corner. I just want to change the position of it.

enter image description here

I want to place the MyLocationButton where the globe button image is showing right now.

Thanks in advance.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Harish Singh
  • 765
  • 1
  • 12
  • 23

3 Answers3

2

The Google Maps SDK for iOS provides some built-in UI controls that are similar to those found in the Google Maps for iOS application. Each control has a pre-determined position relative to the edge of the map. You can move the controls away from the edges by padding the map. A Google Map is designed to fill the entire region defined by the GMSMapView. To add padding to your map, create a UIEdgeInsets object and pass it to the GMSMapView.padding property.

// Insets are specified in this order: top, left, bottom, right
UIEdgeInsets mapInsets = UIEdgeInsetsMake(100.0, 0.0, 0.0, 300.0);
mapView.padding = mapInsets;

For more information, you can check this related SO question 26968364 and 16879694

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31
1

Swift 2.3: Solution to move only the Location Button. I am using pod 'GoogleMaps', '~> 2.1'.

for object in mapView.subviews {
    if object.theClassName == "GMSUISettingsView" {
        for view in object.subviews {
            if view.theClassName == "GMSx_QTMButton" {
              var frame = view.frame
              frame.origin.y = frame.origin.y - 110 // Move the button 110 up
              view.frame = frame
            }
        }
    }
}

Extension to get the Class Name.

extension NSObject {
  var theClassName: String {
    return NSStringFromClass(self.dynamicType)
  }
}

I will update this code to Swift 3.0 as soon as possible. :)

Swift 4.0:

public extension NSObject {
    public var theClassName: String {
        return NSStringFromClass(type(of: self))
    }
}
Etienne Noël
  • 5,988
  • 6
  • 48
  • 75
1
mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 10, right:0)

Swift 3.0, Change location the button