Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change myLocationButton position from a GMSMapView?

Anybody know how to get the instance of the myLocationButton from a GMSMapView instance? Or a way to change the default position? I just need to move it some pixels up.

like image 424
JP Illanes Avatar asked Jun 19 '13 03:06

JP Illanes


3 Answers

According the the issue tracker for this Issue 5864: Bug: GMSMapView Padding appears not to work with AutoLayout there is an easier workaround:

- (void)viewDidAppear:(BOOL)animated {
  // This padding will be observed by the mapView
  _mapView.padding = UIEdgeInsetsMake(64, 0, 64, 0);
}
like image 170
user1312972 Avatar answered Nov 07 '22 09:11

user1312972


Raspu's solution moves the whole GMSUISettingsView including the compass.

I found a solution to move only the Location Button:

for (UIView *object in mapView_.subviews) {
    if([[[object class] description] isEqualToString:@"GMSUISettingsView"] )
    {
        for(UIView *view in object.subviews) {
            if([[[view class] description] isEqualToString:@"UIButton"] ) {
                CGRect frame = view.frame;
                frame.origin.y -= 75;
                view.frame = frame;
            }
        }
        /*        
        CGRect frame = object.frame;
        frame.origin.y += 75;
        object.frame = frame;
        */
    }
};

If you uncomment the three lines you move only the compass (for some reason I'm not able to move the GMSCompassButton View).

like image 4
Alexander Scholz Avatar answered Nov 07 '22 10:11

Alexander Scholz


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 - 110px // 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. :)

like image 3
Henrique Carvalho Avatar answered Nov 07 '22 10:11

Henrique Carvalho