4

I am trying to load places inside Google Map View for iOS6. How to set the frame for the Map ? Currently it is fullscreen

 -(void)loadView {

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

   }

I tried by creating a new (small) view inside the current view and add map inside that,but at that time the page is not getting loaded.It shows a full black screen

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

   }
user2115266
  • 137
  • 1
  • 12

5 Answers5

5

You can try... what is working for me :)

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

implementation file

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];
TonyMkenu
  • 7,597
  • 3
  • 27
  • 49
1

It's hard to say if your problem here is adding the map view or something upstream.

Have you set a breakpoint in -viewDidLoad to ensure that it gets called?

Check the bounds of newView to make sure it's what you expect. Is newView visible? Is it a subview of self.view ?

One trick you can use when trying to ensure your views are where you expect them is to set the background color to something obvious, like red, and then you can see plainly on screen if it's what you expect. If you do this and don't see a red box, then your problem isn't with maps, it's somewhere upstream in the code you haven't shown us.

Good luck.

IMNilesAZ
  • 31
  • 3
1

Create a CGRect with the required frame dimensions and set the MapView frame with method mapWithFrame: and then add the mapview as main subview. Below is the code which explains all. CGRect fr= CGRectMake(0, 44, 768, 960); mapView_ = [GMSMapView mapWithFrame:fr camera:camera]; mapView_.myLocationEnabled = YES; [self.view addSubview:mapView_];

Hawk-Eye
  • 400
  • 1
  • 7
  • 23
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_];
}
Saxon Druce
  • 17,406
  • 5
  • 50
  • 71
0

You need to do like this

 -(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_];
}
byJeevan
  • 3,728
  • 3
  • 37
  • 60
IKKA
  • 6,297
  • 7
  • 50
  • 88