1

I started a brand new Single View project with just Google Maps SDK being integrated in it.

Right now it spans over all the screen (full-size), which I believe is the default setting. I want to reduce it so it doesn't take up space on the top bar and I also want to leave space on the bottom for my buttons. How do I do so?

Here's the only method implemented in my (single) view controller class:

- (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;
}
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70
konyv12
  • 716
  • 2
  • 8
  • 23

3 Answers3

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

check this blog http://vikrambahl.com/google-maps-ios-xcode-storyboards/

Jigar
  • 1,801
  • 1
  • 14
  • 29
  • Got errors for each line: says member reference base type 'int *' is not a structure or union – konyv12 Mar 14 '17 at 11:55
  • @konyv12 add uikit header file and import GMSMapView header file – Jigar Mar 14 '17 at 12:03
  • Thanks it worked. Seems like a weird solution though. Why did it remove the (void) didLoad method altogether (it was specified in the official Google Maps tutorial)? – konyv12 Mar 14 '17 at 12:15
  • @konyv12 if your problem is solved than please accept my answer so useful for other people – Jigar Mar 14 '17 at 12:19
0

It should be like this

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

//bottom view height eg:200 here

Rajesh Dharani
  • 285
  • 4
  • 20
0

To add Google map for limited part of the view controller then follow the following steps (using Storyboard):

  1. Add UIView on existing UIViewController.
  2. In Custome Class, add GMSMapView as Custome Class for that UIView.enter image description here

  3. Create IBOutlet of UIView as mapView.

    @property (weak, nonatomic) IBOutlet GMSMapView *mapView;
    
  4. Give Height/Width or Constraint to mapView.

  5. Your function will look like this:

    - (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;
    }
    
sagar.musale
  • 585
  • 1
  • 7
  • 19