...">

GoogleMaps iPhone

, . GMS , , , , :

- "NSInternalInconsistencyException", : " 0x7ff7fd82def0 GMSMapView , . : (  : 0x0, : 0x7ff7fdc2f470 >

:

self.mapView.myLocationEnabled = YES;
self.mapView.mapType = kGMSTypeNormal;
self.mapView.settings.compassButton = YES;
self.mapView.settings.myLocationButton = YES;

//=>    Listen to the myLocation property of GMSMapView.
[self.mapView addObserver:self
               forKeyPath:@"myLocation"
                  options:NSKeyValueObservingOptionNew
                  context:NULL];


- (void)observeValueForKeyPath:(NSString *)keyPath
                  ofObject:(id)object
                    change:(NSDictionary *)change
                   context:(void *)context
{
if ([keyPath isEqualToString:@"myLocation"] && [object isKindOfClass:[GMSMapView class]])
{   
    appDelegate().curUserLocation = [change objectForKey:NSKeyValueChangeNewKey];

    [self.mapView animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:self.mapView.myLocation.coordinate.latitude
                                                                             longitude:self.mapView.myLocation.coordinate.longitude
                                                                                  zoom:15]];
}
}

      

. observerValueForKey, . .

:

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

[self.mapView removeObserver:self forKeyPath:@"myLocation"];

//=>    Set map delegate to nil (to avoid:   mapView:regionDidChangeAnimated:]: message sent to deallocated instance )
self.mapView.delegate = nil;
self.mapView = nil;
}

      

.

- ? , .

!

+3




2


.. GMSMapView Strong

iOS 8, requestWhenInUseAuthorization

CLLocationManager KVO... .

- Google... 2:

  • KVO
  • CLLocationManager

- ...



PS API

!

UpdatingLocation.. - stopUpdatingLocation

.. ViewDidDisapear

+2




viewWillAppear:, viewWillDisappear, .

viewDidLoad, deinit, . ,



Swift 3

deinit {
     mapView.removeObserver(self, forKeyPath: "myLocation")
}

      

+2









All Articles