iOS / Obj- C - назначить карту Google для пользовательского UIView? - PullRequest
0 голосов
/ 30 мая 2020

Я пытаюсь отобразить свою карту Google в пользовательском UIView, а не в self.view. В настоящее время мой код работает нормально, если я настроил его отображение в self.view; карта отображается со всеми примененными стилями и указанной камерой. Но в ту минуту, когда я пытаюсь отобразить ее в пользовательском UIView (self.mapView), карта отображается, но она полностью пуста (ie. Камера не установлена, нет маркеров, ничего). Есть идеи, почему это?

MapViewController.h

@interface MapViewController : ViewController <CLLocationManagerDelegate, GMSMapViewDelegate> 

@property (strong, nonatomic) IBOutlet GMSMapView *mapView;
@property (nonatomic, strong) IBOutlet GMSCameraPosition *camera;

MapViewController.m

-(void)viewDidLoad {

        self.camera = [GMSCameraPosition cameraWithLatitude:-33.868
                                                                 longitude:151.2086
                                                                      zoom:12];


          self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:self.camera];
          self.mapView.settings.compassButton = YES;
          self.mapView.settings.myLocationButton = YES;


         [self.mapView addObserver:self
                    forKeyPath:@"myLocation"
                       options:NSKeyValueObservingOptionNew
                       context:NULL];

         [self.view addSubview:_mapView];


     NSBundle *mainBundle = [NSBundle mainBundle];
        NSURL *styleUrl = [mainBundle URLForResource:@"style" withExtension:@"json"];
        NSError *error;


        // Set the map style by passing the URL for style.json.
        GMSMapStyle *style = [GMSMapStyle styleWithContentsOfFileURL:styleUrl error:&error];
        NSLog(@"This is what %@", style);

        if (!style) {
          NSLog(@"The style definition could not be loaded: %@", error);
        } else {

            NSLog(@"Style Loaded");
        }



        self.mapView.mapStyle = style;

      dispatch_async(dispatch_get_main_queue(), ^{
             self.mapView.myLocationEnabled = YES;
         });



    }

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

    - (void)observeValueForKeyPath:(NSString *)keyPath
                          ofObject:(id)object
                            change:(NSDictionary *)change
                           context:(void *)context {
      if (!firstLocationUpdate) {

        firstLocationUpdate = YES;
        CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey];
          self.mapView.camera = [GMSCameraPosition cameraWithTarget:location.coordinate
                                                         zoom:14];
      }
    }
...