0

I am trying to make my google maps map view only half of the screen. I have resized the map view to be half the screen and also changed my code so it's only the bounds of the map view which is half the screen but it still goes full screen. Anyone got a solution?

// setting up mapView
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    _mapView = [GMSMapView mapWithFrame:_mapView.bounds 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;

    // Creates a marker in the center of the map.
    GMSMarker *marker2 = [[GMSMarker alloc] init];
    marker2.position = CLLocationCoordinate2DMake(-36.86, 151.20);
    marker2.title = @"Sydney2";
    marker2.snippet = @"Australia2";
    marker2.map = _mapView;

Thanks,

Curtis

Curtis Boylan
  • 827
  • 1
  • 7
  • 23

2 Answers2

1

You may can try to add the _mapView as a subview instead of assigning it to self.view.

[self.view addSubview:_mapView];
riik
  • 4,448
  • 1
  • 12
  • 16
0

You can do it with the help of storyboard.

  • Drag a UIView in your ViewController and add GMSMapView class to the UIView.

  • Set the frame size for your UIView using storyboard. Create outlet for the UIView( name it mapView) and connect it.

  • In your ViewController class under viewDidLoad add these two lines two view the google map.

            GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: YOUR_LATITUDE 
            longitude: YOUR_LONGITUDE zoom:8];
    
            [self.mapView setCamera:camera];
    
  • Add marker to the location using following code.

    GMSMarker *marker = [[GMSMarker alloc]init];
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(YOUR_LATITUDE, YOUR_LONGITUDE);
    
Akash KR
  • 778
  • 3
  • 11