Google Maps iOS [closed]

2019-09-20 16:00发布

I am trying to insert Google Maps in a CGRect in iOS. But the code below still displays the map in the entire iPhone page. How do I fix this

CGRect rect = CGRectMake(50, 10, 200, 200);
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
                                                        longitude:151.2086
                                                             zoom:6];
mapView_ = [GMSMapView mapWithFrame:rect camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
options.title = @"Sydney";
options.snippet = @"Australia";
[mapView_ addMarkerWithOptions:options];

2条回答
Animai°情兽
2楼-- · 2019-09-20 16:31

By default the root view of a view controller is resized to fill the screen.

You would need to add a separate view to be the root view, and then add the map view to it. For example:

self.view = [[UIView alloc] initWithFrame: CGRectZero];
[self.view addSubview: mapView_];
查看更多
别忘想泡老子
3楼-- · 2019-09-20 16:48

A nice way that I've found to work with Google Maps Views is to:

1 - drag a new view object onto your controller or view

2 - size and position accordingly

4 - in identity inspector set class to GMSMapView

5 - control drag using the assistant to give it to your view controller as a property

6 - have everything be the exact size you specified in the editor and treat it basically like an already initialized map view!

查看更多
登录 后发表回答