CSStudent
CSStudent

Reputation: 425

Resizing Google Maps MapView iOS

I've attempted to use the code from the GoogleMapsSDKDemos to resize the mapview to a smaller rectangle on the screen, but it doesn't appear to have any effect. Here is my code:

mapView = [[GMSMapView alloc] initWithFrame:CGRectZero]; mapView.camera = [GMSCameraPosition cameraWithLatitude:38.98549782690282 longitude:-76.94636067188021 zoom:17];

self.view = [[UIView alloc] initWithFrame:CGRectZero];
mapView.autoresizingMask =
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mapView.frame = self.view.frame;
mapView.clipsToBounds = YES;
mapView.myLocationEnabled = YES;
mapView.settings.tiltGestures = NO;
mapView.settings.zoomGestures = NO;

mapView.frame = CGRectMake(0,0, 10, 25);

[self.view addSubview:self.mapView];

That second-to-last line seemingly should limit the MapView to just a small square, but it still takes up the entire screen.

Upvotes: 4

Views: 5976

Answers (2)

Lücks
Lücks

Reputation: 3994

Try this to add the map to the top of view:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
                                                        longitude:longitude
                                                             zoom:10];



mapView_ = [GMSMapView mapWithFrame:CGRectMake(0,0, width, height) camera:camera];
mapView_.delegate = self;
mapView_.myLocationEnabled = YES;
[self.view addSubview:mapView_];

Upvotes: 1

Saxon Druce
Saxon Druce

Reputation: 17624

I would try something like this:

GMSCameraPosition* camera = [GMSCameraPosition 
    cameraWithLatitude: 38.98549782690282 
    longitude: -76.94636067188021 
    zoom: 17];
GMSMapView* mapView = 
    [GMSMapView mapWithFrame: GRectMake(0,0, 10, 25) camera: camera];

Note that the comments on the GMSMapView class in GMSMapView.h say:

This class should not be instatiated directly, instead it must be created with [GMSMapServices mapWithFrame:camera:]

Upvotes: 3

Related Questions