IOS 谷歌地图相机不指向标记

标签 ios google-maps marker google-maps-sdk-ios

我在 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

这是我看到的

enter image description here

标记在澳大利亚铁路上,但相机未指向它且标记不在 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/

相关文章:

ios - 有没有什么办法可以让 VoiceOver 按命令朗读标签?

javascript - 获取 WKWebView 的内容高度不正确

javascript - Angular 2 在更改值后不更新 View

ios - 在 iOS 上使用 OpenCV 实时检测自定义图像标记

ios - 用 UIImages 构建一条蛇

ios - 核心蓝牙,如何确定检测的陈旧性?

javascript - Zoom_changed 监听器对我不起作用

ios - 如何在 iOS 中使用 Google map API 获取附近的地点

google-maps - 调整谷歌地图标记的 svg 图标大小

visual-c++ - 如何将汇编标记放入 C++ 代码 (x64)