MKMapView only shows one annotation after n iterations

I am using the loop below to populate the MapView. However, it always only shows one output at a time, no matter how many iterations I do.

Individual listing of items is also unaffected.

I'm using the original 3.0 SDK with xCode 3.1.3 on osx 10.5.8, the 3.1 SDK changelog doesn't mention anything about any fixes in the MKMapKit framework, so I didn't feel the need to download the 2.5GB file.

    for(NSDictionary* dict in results ){
    NSLog(@"Made Annotation  %@ at N%f E%f", [dict valueForKey:@"location"],[dict valueForKey:@"latitude"],[dict valueForKey:@"longitude"] );
    NSLog(@"List of keys %@", dict);

    LTAnnotation* pin = [[LTAnnotation alloc] initWithTitle: [dict valueForKey:@"location"]
                                     latitude: [dict objectForKey:@"latitude"]
                                    longitude: [dict objectForKey:@"longitude"]
    ];

    [MapView addAnnotation: pin];

}

      

This is derived from the first registration statement

Made Annotation  London at N51.3 E0.07000000000000001
Made Annotation  Amsterdam at N52.22 E4.53

      

And the second dictionary structure

List of keys {
    id = 0;
    latitude = 51.3;
    location = London;
    longitude = 0.07000000000000001;
    time = "12:00-13:00";
}
List of keys {
    id = 1;
    latitude = 52.22;
    location = Amsterdam;
    longitude = 4.53;
    time = "12:00-13:00";
}

      

In case you are interested here my LTAnnotation implementation is

@interface LTAnnotation(Private)
    double longitude;
    double latitude;
@end

@implementation LTAnnotation

@synthesize title;
@synthesize subTitle;
-(id) initWithTitle:(NSString*)pTitle latitude:(NSNumber*)latDbl longitude:(NSNumber*) longDbl{
    self = [super init];

    self.title = pTitle;

    latitude = [latDbl doubleValue];
    longitude = [longDbl doubleValue];
    NSLog(@"Create Annotation for %@ at %fN %fE",pTitle,[latDbl doubleValue],[longDbl doubleValue]);
    return self;

}


-(CLLocationCoordinate2D) coordinate
{
    CLLocationCoordinate2D retVal;

    retVal.latitude = latitude;
    retVal.longitude = longitude;

    return retVal; 
}
@end

      

It all comes together to create this ...

alt text http://img340.imageshack.us/img340/3788/picture1fg.png

Any ideas where I'm going wrong? Thanks to

+2


source to share


2 answers


Two small things I noticed that might help solve the problem:

  • You are not emitting output in the first code example that would create a leak
  • You don't check, "self = [super init];" your second code example was successful ("if (self = [super init]) {...} return self"). NSLog also only outputs the parameters passed to the init method, not the methods of the object instance

And most importantly, I just noticed this in the init method:



latitude = [latDbl doubleValue];
longitude = [longDbl doubleValue];

      

You are not using Objective-C 2 style accessors (self.latitude = ...) and are not storing the auto-implemented value values. This probably means the variables are disappearing and why you can't see the annotations as they don't have valid coordinates.

+1


source


Try to set latitude and longitude as floating.



MKMapView shows incorrectly saved area

+1


source







All Articles