Search code examples
iosgoogle-mapsgoogle-maps-sdk-ios

GMSMarker points not being shown


I have a viewcontroller in a storyboard with a View in it that loads googlemaps. Markers are however, not showing up!

What have I done wrong?

Here is my code.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createBasicGSMView];
}

- (IBAction)AddPointButtonPressed:(id)sender {
    // Creates a marker in the center of the map.
    GMSMarker *CurrentLocationMarker = [[GMSMarker alloc] init];

    CLLocation *CurrentLocationNote = mapView_.myLocation;

    CurrentLocationMarker.position = CLLocationCoordinate2DMake(CurrentLocationNote.coordinate.latitude, CurrentLocationNote.coordinate.longitude);
    CurrentLocationMarker.title = @"Current Location";
    CurrentLocationMarker.snippet = @"This is the place to be";
    [CurrentLocationMarker setMap:mapView_];
}

- (void) createBasicGSMView{
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:1];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    self.mapViewHolder = 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_;
}

Solution

  • Figured it out. had to add the view as a subview:

    [self.view addSubview:mapView_];
    

    Doesnt work otherwise!