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.
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);
}
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).
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With