Search code examples
iosxcodeios6mapsgoogle-maps-sdk-ios

Google Maps iOS


I am trying to insert Google Maps in a CGRect in iOS. But the code below still displays the map in the entire iPhone page. How do I fix this

CGRect rect = CGRectMake(50, 10, 200, 200);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
                                                        longitude:151.2086
                                                             zoom:6];
mapView_ = [GMSMapView mapWithFrame:rect camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
options.title = @"Sydney";
options.snippet = @"Australia";
[mapView_ addMarkerWithOptions:options];

Solution

  • By default the root view of a view controller is resized to fill the screen.

    You would need to add a separate view to be the root view, and then add the map view to it. For example:

    self.view = [[UIView alloc] initWithFrame: CGRectZero];
    [self.view addSubview: mapView_];