Search code examples
iosobjective-cgoogle-maps-sdk-ios

Google map load on subviews in IOS


I have implement google map in IOS . But the problem is I can not implement google map on my custom view (subview) . Thanks in advance .


Solution

  • Create a subview and Define the subview class under GMSMapView

    enter image description here

    - (void)LoadMap {
    
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    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.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
    
    // this line add subView
    [self.view addSubview : mapView_ ];  }