Moving the google maps compass

孤人 提交于 2019-11-28 08:04:24

问题


The new google maps SDK for iOS now has a UI widget for displaying a compass. The only problem is I only see methods to toggle it on or off. Do you know if it's possible to change it's position on the map?

https://developers.google.com/maps/documentation/ios/map#compass


回答1:


-(void)viewDidAppear:(BOOL)animated{
mapView.padding = UIEdgeInsetsMake (64,0,0,0);
}

This Code It will move Compass Button downward in 64 pixel.




回答2:


Not very orthodox but it works.

  for (UIView *view in gmMapView.subviews) {
        NSRange isRange = [view.description rangeOfString:@"GMSCompassButton"];
        if (isRange.location != NSNotFound) {
           CGRect frame = view.frame;
           frame.origin.y=55;
           frame.origin.x=gmMapView.frame.size.width/2;
           [view setFrame:frame];
        }
  }



回答3:


It is not possible to change the location of the compass button. Please file a feature request.




回答4:


Here is the latest workaround which works with SDK 1.5.

- (void)moveCompassButton:(GMSMapView *) map{
    for(UIView *view in [map subviews]){
        NSRange isRange = [view.description rangeOfString:@"GMSUISettingsView"];
        if(isRange.location != NSNotFound){
            for(UIView *subview in [view subviews]){
                NSRange isRange2 = [subview.description rangeOfString:@"GMSCompassButton"];
                if(isRange2.location != NSNotFound){
                    CGRect frame = view.frame;
                    frame.origin.y = 55;
                    frame.origin.x = map.frame.size.width/2 - 10;
                    [view setFrame:frame];
                }
            }
        }
    }
}

You can call this function with your map view as a parameter and you are good to go.




回答5:


The new release of the Google Maps SDK 1.5 includes a paddern property for the GMSMapView. Now it is possible to set the area where UI elements will be shown.



来源:https://stackoverflow.com/questions/16269364/moving-the-google-maps-compass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!