Mil*_*njo 2 objective-c google-maps-sdk-ios
因此,我按照本指南介绍了如何将Google地图添加到iOS应用程序中,一切正常.但我想做的是分配地图,而不是self.view我自己拖到故事板内部(?)另一个视图的自定义视图,因为当self.view我添加地图时我无法添加其他元素,如按钮,或者好吧,我可能但我不知道怎么做.
码:
// Start locationmanager
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
// Set up the startposition for the camera when the app first starts.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:59.34702 longitude:18.04053 zoom:10];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = mapView_;
Run Code Online (Sandbox Code Playgroud)
所以我在UIView当前包含地图的视图中创建了一个内部,然后用ctrl拖动它来创建一个名为mapView的插座viewController.所以我改变了代码行
self.view = _mapView;
Run Code Online (Sandbox Code Playgroud)
至
self.mapView = _mapView;
Run Code Online (Sandbox Code Playgroud)
但这似乎根本不起作用,只是空白.这两个self.view和self.mapsView是的情况下UIView,为什么不这样不行?
更新:
这就是我的viewDidLoad看起来像atm:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.mapView addSubview:mapView_];
// Start locationmanager
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
// Standard cameraposition
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:59.34702 longitude:18.04053 zoom:10];
mapView_ = [GMSMapView mapWithFrame:self.mapView.frame camera:camera];
self.mapView = mapView_;
}
Run Code Online (Sandbox Code Playgroud)
小智 11
请执行下列操作:
GMSMapView在IB的身份检查器中将自定义视图类更改为mapView在您的视图控制器中创建此自定义视图的出口(注意插座类型也是GMSMapView)因此,现在当您启动应用程序时,将创建此实例,它将在地图上显示默认位置(伦敦附近).现在,您只需创建一个摄像头并将其添加到地图对象中.在ViewDidLoad方法中添加以下代码:
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:45.24 longitude:19.84 zoom:6];
// set camera location to Novi Sad, Serbia :-)
[self.mapView setCamera:camera]; // set the camera to map
Run Code Online (Sandbox Code Playgroud)
多数民众赞成,您不需要mapView_Google示例代码中的实例变量,也不需要Google示例中的任何其他代码.请享用!
| 归档时间: |
|
| 查看次数: |
3690 次 |
| 最近记录: |