我是 IOS 开发的新手,我正在尝试将 Google 地图添加到示例应用程序中。我正在使用https://developers.google.com/maps/documentation/ios/上的教程。除了谷歌地图占据了整个屏幕之外,一切都运行良好。显示谷歌地图的代码是
#import <GoogleMaps/GoogleMaps.h>
#import "DemoViewController.h"
@implementation DemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
longitude:151.2086
zoom:6];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = camera.target;
marker.snippet = @"Hello World";
marker.animated = YES;
self.view = mapView;
}
@end
谷歌地图之所以占据整个屏幕是因为self.view = mapView; . 我怎样才能添加谷歌地图,这样它就不会占据全屏。
我尝试使用 SubView 如下,但它仍然无法正常工作。代码是:
视图控制器.h
@interface ViewController : UIViewController
@property UIView *myView;
@end
视图控制器.m
#import "ViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface ViewController ()
@end
@implementation ViewController{
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect viewRect = CGRectMake(0, 0, 100, 100);
_myView = [[UIView alloc] initWithFrame:viewRect];
[self.view addSubview:_myView];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
// 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_;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end