4

我正在尝试在 iOS6 的 Google Map View 中加载地点。如何设置地图的框架?目前是全屏

 -(void)loadView {

   GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
                                                        longitude:76.316142
                                                             zoom:15];
   mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
   self.view = mapView_;

   }

我尝试在当前视图中创建一个新的(小)视图并在其中添加地图,但当时页面没有被加载。它显示一个全黑屏

 -(void)loadView {

  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
                                                        longitude:76.316142
                                                             zoom:15];
   mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

   [self.view Addsubview:newView];
   self.newView = mapView_;

  // I also tried like this - [self.newView Addsubview:mapView_;

   }
4

5 回答 5

5

你可以试试......什么对我有用:)

//header file
...
@property (nonatomic, weak) IBOutlet GMSMapView *mapView;
@property (weak, nonatomic) IBOutlet UIView *subview; //viewForMap
...

执行文件

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.8683
                                                            longitude:76.2086 zoom:6
                                                              bearing:0
                                                         viewingAngle:0
                                                                ];
    self.mapView = [GMSMapView mapWithFrame:_subview.bounds camera:camera];
  [_subview addSubview:_mapView];
于 2013-03-28T20:32:25.820 回答
1

创建具有所需框架尺寸的 CGRect 并使用方法设置 MapView 框架,mapWithFrame:然后将 mapview 添加为主子视图。以下是解释所有内容的代码。 CGRect fr= CGRectMake(0, 44, 768, 960); mapView_ = [GMSMapView mapWithFrame:fr camera:camera]; mapView_.myLocationEnabled = YES; [self.view addSubview:mapView_];

于 2013-03-29T06:32:04.867 回答
1

很难说你的问题是添加地图视图还是上游的东西。

您是否在 -viewDidLoad 中设置了断点以确保调用它?

检查 newView 的边界以确保它是您所期望的。newView 可见吗?它是 self.view 的子视图吗?

当您试图确保您的视图位于您期望的位置时,您可以使用的一个技巧是将背景颜色设置为明显的颜色,例如红色,然后您可以在屏幕上清楚地看到它是否符合您的期望。如果您这样做并且没有看到红色框,那么您的问题不在于地图,而是您尚未向我们展示的代码的上游某处。

祝你好运。

于 2013-03-28T15:44:50.450 回答
0

你需要这样做

 -(void)loadView {

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
                                                        longitude:76.316142
                                                             zoom:15];

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

    [self.view addSubview:newView];

    [self.newView addSubview:mapView_];
}
于 2013-11-13T11:31:49.463 回答
0

I don't think loadView is called when you are using a xib. I haven't tried using the Google Maps SDK for iOS with a xib, as I create all of my views programmatically.

Maybe you could add your map view in viewDidLoad? So for example:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.00989
                                                    longitude:76.316142
                                                         zoom:15];
    mapView_ = [GMSMapView 
        mapWithFrame: CGRectMake(
            0, 0, 
            self.newView.frame.size.width, self.newView.frame.size.height)               
        camera: camera];

   [self.newView addSubview: mapView_];
}
于 2013-03-28T06:51:38.460 回答