如何在ViewController中设置Google Maps应用的大小?

时间:2017-03-14 11:25:17

标签: ios objective-c xcode google-maps gmsmapview

我开始了一个全新的单一视图项目,其中只集成了Google Maps SDK。

现在它横跨所有屏幕(全尺寸),我相信这是默认设置。我想减少它,所以它不占用顶部栏上的空间,我也想在我的按钮的底部留出空间。我该怎么做?

这是我(单个)视图控制器类中实现的唯一方法:

- (void)loadView {
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
self.view = mapView;

// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"Sydney";
marker.snippet = @"Australia";
marker.map = mapView;
}

3 个答案:

答案 0 :(得分:2)

1)Add a UIView into the ViewController where you want and set your custom size
2)set it's type to be GMSMapView in IdentityInspector

delcare IBOutlet in .H file

@property (weak, nonatomic) IBOutlet GMSMapView *map1;

.M

- (void)viewDidLoad {
    [super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285
                                                                longitude:103.848
                                                                     zoom:12];
        self.map1.camera = camera;
        self.map1.delegate=self;
        self.map1.accessibilityElementsHidden = NO;
        self.map1.indoorEnabled = NO;
        self.map1.settings.myLocationButton = YES; 
        dispatch_async(dispatch_get_main_queue(), ^{
            self.map1.myLocationEnabled = YES;
        });
}

查看此博客http://vikrambahl.com/google-maps-ios-xcode-storyboards/

答案 1 :(得分:0)

应该是这样的

GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(0, 64, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height -200) camera:camera];

//底部视图高度例如:200这里

答案 2 :(得分:0)

要为视图控制器的有限部分添加Google地图,请按照以下步骤(使用故事板):

  1. 在现有UIView上添加UIViewController
  2. 在Custome Class中,为GMSMapView添加UIView作为Custome类。enter image description here

  3. 创建UIView的IBOutlet作为mapView。

    @property (weak, nonatomic) IBOutlet GMSMapView *mapView;
    
  4. 为mapView提供高度/宽度或约束。

  5. 您的功能如下所示:

    - (void)loadView {
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
      GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];
      self.mapView.myLocationEnabled = YES;
    
      // Creates a marker in the center of the map.
      GMSMarker *marker = [[GMSMarker alloc] init];
      marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
      marker.title = @"Sydney";
      marker.snippet = @"Australia";
      marker.map = self.mapView;
    }