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

   }
4

5 回答 5

3

终于找到了解决办法。去掉 loadview 方法,在视图 did load 方法中放入如下代码:

-(void)viewDidLoad{
    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];

    mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 100, 100) camera:camera];
    [self.view addSubview:mapView_];
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.

    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 = mapView_;
}
于 2013-05-18T18:09:29.020 回答
1

尝试

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

[self.view addSubview:mapView_];
于 2013-04-10T18:54:32.030 回答
1

如果你放入 loadView 它不会有一个视图.. xib 甚至没有加载...把它放在viewDidLoad

mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
[self.view addSubview:mapView_];
于 2013-04-19T07:57:47.163 回答
1

检查 GMSMapView 的 @property 声明,如果它是弱属性,则使其变强。

@property(强,非原子)GMSMapView *mapView;

于 2015-09-09T11:08:48.057 回答
0

通过从我的代码中删除 func loadView 解决了我的问题

    override func loadView() {

}

或者通过将这行代码放在 loadView 中

    override func loadView() {
            self.view = GMSMapView(frame: UIScreen.main.bounds)
}
于 2018-03-11T20:55:06.357 回答