I implemented the GMSMapView via the Googla Maps iOS SDK
the example code from Google suggests to declare the view more or less just dropping this method in your code
- (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];
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_;
}
it automagically works, but the mapView happens to cover my navigationItem it's clear that the maps take its dimension at the initWithFram:CGRectZero but simply changing the parameter to a custom CGRect
CGRect square = CGRectMake(100, 100, 100, 100);
haven't worked for me, any other suggestion? i only need to display the map between the Nav Item and the Tab Bar (but the second doesn't happen to be covered)
Make sure your view controller for the map is part of a navigation stack of a UINavigationController
. I had no problems pushing a UITabBarController
with a map and a list tab onto a view controller embedded in a UINavigationController
. This way the navigationbar view belongs only to the UINavigationController
and the map controller view shouldn't cover it.
The problem was that the mapView_ was being set as the whole view
self.view = mapView_;
calculating the correct dimension and adding it as a subview was the correct way to solve it
CGRect f = self.view.frame;
CGRect mapFrame = CGRectMake(f.origin.x, 44, f.size.width, f.size.height);
mapView_ = [GMSMapView mapWithFrame:mapFrame camera:camera];
[self.view addSubview:mapView_];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.