问题
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;
}
回答1:
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/
回答2:
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
回答3:
To add Google map for limited part of the view controller then follow the following steps (using Storyboard):
- Add
UIView
on existingUIViewController
. In Custome Class, add
GMSMapView
as Custome Class for thatUIView
.Create IBOutlet of
UIView
as mapView.@property (weak, nonatomic) IBOutlet GMSMapView *mapView;
Give Height/Width or Constraint to mapView.
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; }
来源:https://stackoverflow.com/questions/42784690/how-do-i-set-the-size-of-google-maps-app-within-my-viewcontroller