我在 Storyboard中有一个 View Controller ,我想在上面显示一个谷歌地图
一切顺利,我得到了,我可以显示 map
我的问题是相机没有指向标记
这是我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"we are in the show stadium");
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.mynewmap = 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_;
}
其中 mynewmap
是一个 UIView outlet
这是我看到的
标记在澳大利亚铁路上,但相机未指向它且标记不在 map 上
最佳答案
如果您正在使用 Storyboard,请在 Interface Builder 中将 mynewmap 的类设置为 GMSMapView。
并且在 viewDidLoad 中只需添加相机,您不需要分配 View ,因为它已经分配好了:
- (void)viewDidLoad
{
[super viewDidLoad];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:6];
self.mynewmap.camera = camera;
}
或者尝试不使用零矩形创建您的 View .. CGRectZero...您可以尝试:
mapView_ = [GMSMapView mapWithFrame:self.mynewmap.frame camera:camera];
关于IOS 谷歌地图相机不指向标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24058820/