Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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];
share|improve this question
I think you should use GMSMarkerOptions *options = [[GMSMarkerOptions alloc] initWithFrame:rect]; – Arpit Kumar Mar 24 at 9:44
@ArpitKumar: GMSMarkerOptions does not have an initWithFrame method. – Saxon Druce Mar 24 at 12:44

1 Answer

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_];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.