在我的iOS应用程序中,我有一个父mapViewController
(UIView),我尝试通过执行[self.mapViewContainer addSubview:mapView_];
在初始化mapView_时,我尝试使用容器UIView的边界,以便通过执行以下内容来完成整个空间:
mapView_ = [GMSMapView mapWithFrame:self.mapViewContainer.bounds camera:camera];
虽然地图看起来很好,但每当我尝试将地图置于坐标中心时,应该居中的坐标位于右下角或底部中心,具体取决于potrait / landscape模式。
我的印象是地图超出了我无法解决的预期边距。
有没有办法轻松完成我想要做的事情。我已经尝试将mapView_初始化为
GMSMapView *mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
但那只是显示一个空屏幕。
答案 0 :(得分:0)
由于您使用的是CGRectZero.so,因此未显示以后的Google地图行,这就是为什么不显示您的Google地图。
GMSMapView *mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
这段代码对我有用......你可能会受到帮助..
查看我的代码...您在视图控制器中显示您的Google地图。
GMSCameraPosition *camera ;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
camera = [GMSCameraPosition cameraWithLatitude:<pass your latitude>
longitude:<pass your longitude>
zoom:17];
}
else
{
camera = [GMSCameraPosition cameraWithLatitude:<pass your latitude>
longitude:<pass your longitude>
zoom:16];
}
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(0,0, self.view.frame.size.width , self.view.frame.size.height) camera:camera];
mapView.myLocationEnabled = YES;
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
[mapView setMinZoom:17 maxZoom:23];
}
else
{
[mapView setMinZoom:16 maxZoom:20];
}
// [mapView setMinZoom:16 maxZoom:20];
// mapView.settings.indoorPicker =YES;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(<pass your latitude>,<pass your longitude>);
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.title =@"Driver's location";
marker.icon = [UIImage imageNamed:@"GoogleIcon"];
marker.map = mapView;
[self.view addSubview:mapView];
[self.view insertSubview:self.btnRefresh aboveSubview:mapView];
答案 1 :(得分:0)
如果可能,您可以将Google地图视图放在故事板中。
如果你想在代码中做,避免使用框架,请尝试使用约束。