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.
4 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);
}

- 166
- 1
- 2
-
Even if this will apply a padding to all the UI, this seems to be the way to go since 1.5, so I will move the ticket to you. – JP Illanes Oct 07 '13 at 00:43
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).

- 2,100
- 1
- 20
- 35
-
You are right, your answer is more accurate, so I'm giving the ticket to you. – JP Illanes Jul 29 '13 at 00:37
-
this answer change the place of google icon don't know how not compass button – ahmedHegazi Sep 07 '15 at 12:51
-
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. :)

- 113
- 1
- 6
Right now the only way I have found is this way:
//The method 'each' is part of Objective Sugar
[googleMapView.subviews each:^(UIView *object) {
if([[[object class] description] isEqualToString:@"GMSUISettingsView"] )
{
CGPoint center = object.center;
center.y -= 40; //Let's move it 40px up
object.center = center;
}
}];
It's working fine, but an official way would be better.
This works for 1.4.0 Version. For previous versions, change @"GMSUISettingsView"
for @"UIButton"
.

- 3,665
- 39
- 56