应用程序崩溃没有任何错误

时间:2014-06-05 09:30:14

标签: ios iphone ipad google-maps google-maps-sdk-ios

我正在尝试整合Google地图sdk并跟随this link to start from google。我创建了API密钥并在appDelegate中使用了它。我在我的ViewController.m中编写了下面的代码,我已经导入了所有需要的框架,并且还将-ObjC放在其他链接器标志中,但是应用程序在运行时仍然崩溃。我使用了断点但没有显示日志。以下是整个代码,并没有使用任何插座。

 #import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; // crashing here, even gave different frames rather CGRectZero
    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_;
}

@end

DEMO SAMPLE LINK

2 个答案:

答案 0 :(得分:1)

为什么要将CGRectZero传递给地图框架?

请尝试以下代码: -

- (void)viewDidLoad {
 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20 zoom:6];

mapView_ = [GMSMapView mapWithFrame:CGRectMake(0, 0, 320, 320) camera:camera]; // crashing here
mapView_.myLocationEnabled = YES;
[self.view addSubview: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_;

}

答案 1 :(得分:1)

我下载了代码并运行它。它运作得非常好。只需删除旧应用并清除目标即可。重新安装该应用程序。它应该工作正常。