简体   繁体   English

谷歌地图iOS SDK崩溃

[英]Google Maps iOS SDK crash

I use google maps iOS SDK with storyboard. 我使用谷歌地图iOS SDK与故事板。 Application starting with Navigation View Controller that has a Root View Controller with map. 应用程序从具有带有地图的根视图控制器的导航视图控制器开始。

@implementation MyViewController
@synthesize btnMyLock;
@synthesize btnNearby;

GMSMapView *mapView_;
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:20
                                                        longitude:20
                                                             zoom:0];

     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 setIcon:[UIImage imageNamed:@"pin"]];
     marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
     marker.title = @"Sydney";
     marker.snippet = @"Australia";
     marker.map = mapView_;

     mapView_.settings.compassButton = YES;

     [mapView_ addSubview:btnMyLock];
     [mapView_ addSubview:btnNearby]; 
}

Button btnMyLock push the Table View Controller. 按钮btnMyLock按下表视图控制器。 In iOS 7 it's ok. 在iOS 7中没关系。 But iOS 6 my app crashes. 但iOS 6我的应用程序崩溃了。 Sometimes crash with EXC_BAD_ACCESS (code=1) or code=2 有时会因EXC_BAD_ACCESS(代码= 1)或代码= 2而崩溃

我使用Autolayout视图的问题。

you forgot step 4: " Drag the GoogleMaps.bundle " from the Resources folder to your project. 你忘了第4步:“ 将GoogleMaps.bundle ”从Resources文件夹拖到你的项目中。

I suggest putting it in the Frameworks group. 我建议把它放在Frameworks组中。 When prompted, ensure "Copy items into destination group's folder" is not selected. 出现提示时,确保未选中“将项目复制到目标组的文件夹”。 i encountered the same problem, and this fixed it. 我遇到了同样的问题,这解决了它。

I don't know if it's causing the problem, but I wouldn't do: 我不知道它是否导致问题,但我不会这样做:

self.view = mapView_;

Just add the mapView_ as a subview, like: 只需将mapView_添加为子视图,例如:

[self.view addSubview:mapView_];

In general EXC_BAD_ACCESS crashes are caused when you are mismanaging memory (eg an object is being deallocated prematurely). 一般情况下,EXC_BAD_ACCESS崩溃是在您对内存管理不善时造成的(例如,对象过早地被解除分配)。 Try to find out what object the crash is happening on. 试着找出崩溃发生的对象。


Create your buttons in code, not from the xib as IBOutlets. 在代码中创建按钮,而不是作为IBOutlets从xib创建。 Otherwise they are not loaded since you are not using the xib. 否则它们不会加载,因为您没有使用xib。

Use this code when you use Google map and then check its not crash when you navigate to another screen. 使用Google地图时使用此代码,然后在导航到其他屏幕时检查其是否崩溃。

- (void)dealloc {
[super dealloc];
[mapView_ removeObserver:self
              forKeyPath:@"myLocation"
                 context:NULL];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM