Ricardo Macario
Ricardo Macario

Reputation: 213

Coordinates, my location, and markers not appearing in the map

I have been battling with google maps ios sdk for a couple hours, and I've a problema I haven't been able to solve. So here is what is happening:

I have a view controller in interface builder and with it .m and .h implmentation. The view controler has a view, and inside that view there is another view which is the on that holds the map, so in the identity inspector on the custom class it is set to GMSMapView.

This view has an outlet to the .h implementation and its is called mapView. And on the .m I have the following code:

{

[super viewDidLoad];

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.49101

 longitude:-66.902061

 zoom:4];

 self.mapView = [GMSMapView mapWithFrame:[self.mapView bounds] camera:camera];

 self.mapView.myLocationEnabled = YES;



 GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];

 options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);

 options.title = @"Sydney";

 options.snippet = @"Australia";

 [self.mapView addMarkerWithOptions:options];

}

As you can see I create the camera, then the map with the bounds of the view that is on interface builder (mapView). Now this is what is not working:

1) No matter what coordinates I enter the map always starts in England, I believe on (0,0) coordinates 2) My location doesn't appear 3)The marker doesn;t appear either. 4) IMPORTANT: the map is appearing but always over England.

I honestly don't know what is happening, I believe it has to do with the -(void)viewDidLoad Because if I use the code that google provides writing the code on the loadView method it works, but the problem on doing it that way is that you can't access the views that I created on interface builder.

Thank you very much!

Upvotes: 0

Views: 368

Answers (1)

Ricardo Macario
Ricardo Macario

Reputation: 213

So I found an answer to the problem, without using a view in interface builder, all is donde programmatically. Here is the solution:

-(void)viewDidLoad{ [super viewDidLoad];

mapView = [[GMSMapView alloc] initWithFrame:CGRectZero];

[mapView setFrame:CGRectMake(0, 0, 400, 400)];  ////here you will have to specify the bounds of the view through CGRectMake

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10.49101

                                                         longitude:-66.902061

                                                              zoom:4];

 [mapView setCamera:camera];

 mapView.myLocationEnabled = YES;


 GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];

 options.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);

 options.title = @"Sydney";

 options.snippet = @"Australia";

 [mapView addMarkerWithOptions:options];

 [self.view addSubview:mapView];

 [self.view sendSubviewToBack:mapView]; // just in case you need to send the map to the back, I do

}

Upvotes: 0

Related Questions