سؤال

I am trying to integrate the google map sdk and followed this link to start from google. I have created the API key and used it in appDelegate. I wrote below code in my ViewController.m and I have imported all the frameworks required, and also put the -ObjC in other linker flag but still the app is crashing on run time. I have used breakpoints but no log is been shown up. Below is the entire code and haven't used any outlet.

 #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

هل كانت مفيدة؟

المحلول

I downloaded the code and run it. It works perfectly well. Just remove the old app and clear the target. Re-install the app. It should work fine.

نصائح أخرى

Why do you pass CGRectZero to the frame of the map?

Try the following code:-

- (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_;

}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top