How to change myLocationButton position from GMSMapView?

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

+4
source share
4 answers

According to the tracker for this problem. Problem 5864: Error: GMSMapView Padding does not work with AutoLayout , there is an easier way:

- (void)viewDidAppear:(BOOL)animated { // This padding will be observed by the mapView _mapView.padding = UIEdgeInsetsMake(64, 0, 64, 0); } 
+13
source

The Raspu solution moves the entire 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 only move the compass (for some reason I cannot move the GMSCompassButton view).

+4
source

Swift 2.3: Solution for moving only location buttons. I am using the 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. :)

+3
source

Currently, the only way I have found is this:

 //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 move it 40px up object.center = center; } }]; 

This works great, but an official way would be better.

This works for version 1.4.0. For previous versions, change @"GMSUISettingsView" to @"UIButton" .

0
source

Source: https://habr.com/ru/post/1486956/


All Articles