Warning in custom map iPhone Annotations

I am using a custom map annotation class to display a map on an iPhone. Whenever I exit the map view from the stack of the navigation bar, I usually see some warnings in the console.

MapAnnotation was released, and key value observers were still registered. Observational information has leaked and may even be erroneously tied to another object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here is the current observation information:

I do not use KVO in my code, so I can’t understand why I get these warnings

+7
source share
4 answers

Latitude and longitude have different boundaries:

  • (- 90, 90) for Lat
  • (- 180, 180) for Long

Passing a value outside of these bounds will free up the custom class and therefore give you the error you are getting. Make sure you pass the correct values ​​for latitude and longitude.

It would be nice if Apple would pass a restrictive bug for this instead of an early release bug. That would save me about 5 hours

+30
source

I was getting the same error as you:

An instance 0xa975400 of class xxxxxx was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here the current observation info: <NSKeyValueObservationInfo 0xa980eb0> ( <NSKeyValueObservance 0xa980e70: Observer: 0xa94f8a0, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0xa980ef0> 

As stated here, this was due to the fact that I was adding MKAnnotation with an invalid coordinate for MKMapView.

My solution was to create a function to check the actual coordinate.

Location + MKAnnotation.m

I created a category for my Place class and

 #import "Place.h" #import <MapKit/MapKit.h> @interface Place (MKAnnotation) <MKAnnotation> - (BOOL)coordinateIsValid; ... @end 

Location + MKAnnotation.m

 @implementation Place (MKAnnotation) - (BOOL)coordinateIsValid { return CLLocationCoordinate2DIsValid(CLLocationCoordinate2DMake([self.latitude doubleValue],[self.longitude doubleValue])); } ... @end 

I only add annotation to my ViewController if the coordinate is valid.

 if([p coordinateIsValid]) { [self.mapView addAnnotation:p]; } 
+7
source

Fixed. I used the wrong pair of latitudes and longitudes in the annotations, I changed the same thing and now everything seems perfect, and the warning also disappeared.

+1
source

Do you create an auto-implementation of your annotation before adding it to MapView?

If so, just select it, add it to MapView and then release it.

0
source

All Articles