0

I'm getting crashes while working with MKAnnotation implementation

*** Terminating app due to uncaught exception NSRangeException, reason: Cannot remove an observer MKMapAnnotationManager for the key path "coordinate" from DevicesGroupAnnotation because it is not registered as an observer.

I've implemented coordinate property in following way

@synthesize coordinate = _coordinate;
@synthesize deviceInfos = _deviceInfos;

- (void)setDeviceInfos:(NSArray *)deviceInfos {
    _deviceInfos = deviceInfos;
    self.coordinate = [[self class] coordinateFromDeviceInfosGroup:self.deviceInfos];
}

- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate {
    _coordinate = newCoordinate;
}

What am I doing wrong? What requirements exists on coordinate property implementation?

Sarat Patel
  • 856
  • 13
  • 32
BergP
  • 3,453
  • 4
  • 33
  • 58
  • It seems problem with your Notification settings. Are you adding and removing those annotations frequently? – Mrunal Dec 19 '14 at 08:56
  • @Mrunal I'm sorry, what is "Notification settings"? Yep, I'm adding and removing annotations frequently. – BergP Dec 19 '14 at 09:00
  • @BergP are you implementing custom annotation? – Adeel Ur Rehman Dec 19 '14 at 09:02
  • This seems a duplicate of this question: http://stackoverflow.com/questions/11012067/mkmapview-removing-annotation-causes-app-crash – Mrunal Dec 19 '14 at 09:02
  • @AdeelUrRehman Yes I am. – BergP Dec 19 '14 at 09:06
  • Then you are missing two required methods of MKAnnotation that is `-(NSString *)title` and `-(NSString *)subtitle` – Adeel Ur Rehman Dec 19 '14 at 09:08
  • @AdeelUrRehman no, they are optional – BergP Dec 19 '14 at 09:09
  • is this your class method `coordinateFromDeviceInfosGroup`? – Adeel Ur Rehman Dec 19 '14 at 09:16
  • 1
    may be coordinate are not valid, thats causing to remove the coordinate observer. check once if coordinates are valid with CLLocationCoordinate2DIsValid(). – Pawan Rai Dec 19 '14 at 09:21
  • @AdeelUrRehman Yep, it is class method – BergP Dec 19 '14 at 09:21
  • I cant understand that why you are not calling the class method like this `self.coordinate = [self coordinateFromDeviceInfosGroup:self.deviceInfos];` – Adeel Ur Rehman Dec 19 '14 at 09:29
  • also when this statement is called `self.coordinate = [self coordinateFromDeviceInfosGroup:self.deviceInfos];` your second setter function will be called which is `- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate` – Adeel Ur Rehman Dec 19 '14 at 09:30
  • I have always seen this "cannot remove observer" error with annotations when the coordinates are not valid. Make sure the latitude is from -90 to +90 and the longitude is from -180 to +180. –  Dec 19 '14 at 12:18

0 Answers0