【问题标题】:Issue Implementing the Google Maps API Into iOS Application Project将 Google Maps API 实施到 iOS 应用程序项目中的问题
【发布时间】:2015-03-02 08:50:41
【问题描述】:

我可能遗漏了一些东西,但我按照Google Maps SDK for iOS Site 中指示的步骤操作,但到目前为止我还没有成功。我尝试运行他们在页面底部的示例代码,但我的编译器一直在用未捕获的异常困扰我。

这是我的实现:

@implementation ViewController {
    GMSMapView *mapView_;
}

在 viewDidLoad 中紧随其后:

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
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_;

我确实包含了行:

[GMSServices provideAPIKey:@"API Key"];

并用我的实际 API 密钥替换 API 密钥字符串。然而我在编译时得到了这个。

我使用了一个断点,异常似乎是在执行这一行时产生的:

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

非常感谢您的任何帮助。

【问题讨论】:

    标签: ios objective-c xcode google-maps


    【解决方案1】:

    我猜它需要一个最小帧大小。我在文档中没有看到任何内容,但我会试试这个...

    mapView_ = [GMSMapView mapWithFrame:CGRectMake(0,0, 200, 200) camera:camera];
    

    或者你想要的任何框架尺寸,实际宽度和高度。

    编辑

    在进一步审查您的代码后,我看到了

    self.view = mapView_;
    

    mapView_ 实际上可能不是 GMSMapView。

    编辑编辑

    在获得完整的错误日志后,这听起来像是一个导入或设置问题。

    我会验证没有遗漏任何需要的导入,并且正确添加了所需的链接器标志 -ObjC。

    希望对您有所帮助 =)

    【讨论】:

    • 您能否向上滚动到我在您的日志中看到的异常的顶部,看看为什么它说它正在崩溃?
    • 原因是:[GMSMapView animateToCameraPosition:]:无法识别的选择器发送到实例(我猜是一个十六进制编号,指的是某个内存位置)。
    • 很抱歉没有包含它,但是 mapView_ 在实现开始时被实例化为 GMSMapView。我的错。
    • @DAB 你能把那行添加到你的问题中吗?听起来如何声明可能存在一些问题。这至少可以解释为什么您会得到无法识别的选择器。
    • 我还添加了日志的屏幕截图。
    猜你喜欢
    • 2012-12-30
    • 2023-03-17
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多