0

When I tried to add annotation on mapview using MKPlacemark using this code:

for(int i = 0; i < [array count]; i++){
        UsersModel *model = [array objectAtIndex:i];

        CLLocationCoordinate2D newCoordinate;
        newCoordinate.latitude = model.coordinate.latitude;
        newCoordinate.longitude = model.coordinate.longitude;

        NSLog(@"%f",model.coordinate.latitude);
        NSLog(@"%f",model.coordinate.longitude);

        //mPlaceMark = [[MKPlacemark alloc] initWithCoordinate:newCoordinate addressDictionary:nil];

        MKPlacemark *placeMark = [[MKPlacemark alloc] initWithCoordinate:newCoordinate addressDictionary:nil];

        //[self.mapView addAnnotation:mPlaceMark];
        [self.mapView addAnnotation:placeMark];
        //[placeMark retain];
        NSLog(@"%@", self.mPlaceMark);
    }

Then it gives an error on my console:

An instance 0x1d58be70 of class MKPlacemark 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's the current observation info:
<NSKeyValueObservationInfo 0x1d53de10> (
<NSKeyValueObservance 0x1d58af30: Observer: 0x1d576690, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0x1d58af90>
)
kiritsuku
  • 52,967
  • 18
  • 114
  • 136
  • Are all the latitudes in the range -90 to +90 and are all the longitudes in the range -180 to +180? Enhance the NSLogs (eg. `NSLog(@"latitude = %f",model.coordinate.latitude);`) so you can tell what the numbers refer to. See http://stackoverflow.com/questions/5872547/warning-in-custom-map-annotations-iphone?lq=1. –  Jan 30 '13 at 13:25

1 Answers1

0

Seemingly, you forgot to remove some abserver. Try using this code in your class dealloc method.

 for (id <MKAnnotation> annotation in self.mapView.annotations)
 {
      [[self.mapView viewForAnnotation:annotation] removeObserver:self]; // NOTE: remove ALL observer!
 }

You should also remember to nil your map delegate:

 self.mapView.delegate = nil;
sergio
  • 68,819
  • 11
  • 102
  • 123
  • Actually I am using ARC so, I don't have dealloc method on my code. – Lycan Sayas Jan 31 '13 at 03:35
  • You can surely define a `dealloc` method when using ARC. What you cannot do is calling `release`. Even with ARC, an object will be deallocated; only, when `dealloc` is executed cannot be controlled via retain/release... http://stackoverflow.com/questions/7292119/custom-dealloc-using-arc-objective-c – sergio Jan 31 '13 at 10:55