【问题标题】:Embed Google Maps in UIView with correct Frame使用正确的框架在 UIView 中嵌入谷歌地图
【发布时间】:2015-10-29 01:49:52
【问题描述】:

在我的 iOS 应用程序中,我有一个父 mapViewController(UIView),我尝试通过执行 [self.mapViewContainer addSubview:mapView_]; 将其添加到 Google 地图子视图

在初始化 mapView_ 时,我尝试使用容器 UIView 的边界,以便它通过执行以下操作来利用整个空间:

mapView_ = [GMSMapView mapWithFrame:self.mapViewContainer.bounds camera:camera];

虽然地图看起来很好,但每当我尝试将地图以坐标为中心时,应该居中的坐标要么位于右下角,要么位于底部中心,具体取决于纵向/横向模式。

我的印象是地图超出了预期的边距,我无法修复。

有什么方法可以轻松完成我想做的事情。我尝试将 mapView_ 初始化为

GMSMapView *mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

但这只是显示一个空白屏幕。

【问题讨论】:

    标签: ios objective-c google-maps uiview


    【解决方案1】:

    如果可能,您可以将 Google 地图视图放置在情节提要中。

    如果你想在代码中做,避免使用框架,尝试使用约束。

    【讨论】:

      【解决方案2】:

      因为您使用 CGRectZero.so 这就是为什么不显示您的谷歌地图,所以未显示以下行谷歌地图。

      GMSMapView *mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
      

      这段代码对我有用……你可能会得到帮助……

      查看我的代码...您在视图控制器中显示您的谷歌地图。

       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];
      

      【讨论】:

      • 它产生的结果与 mapView_ = [GMSMapView mapWithFrame:self.mapViewContainer.bounds camera:camera];
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 2016-10-27
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多