Google Maps iOS [closed]

别说谁变了你拦得住时间么 提交于 2019-12-13 08:35:01

问题


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

回答1:


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



回答2:


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!



来源:https://stackoverflow.com/questions/15596572/google-maps-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!