我使用下面的循环来填充我的 MapView。但是,无论我进行多少次迭代,它总是一次只显示一个引脚。
单独声明项目似乎也没有影响。
我在 osx 10.5.8 上使用带有 xCode 3.1.3 的初始 3.0 SDK,3.1 SDK 更改日志没有提到对 MKMapKit 框架的任何修复,所以我觉得不需要下载 2.5GB文件。
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];
}
这是第一个日志记录语句的输出
Made Annotation London at N51.3 E0.07000000000000001
Made Annotation Amsterdam at N52.22 E4.53
第二个是字典的结构
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";
}
如果您感兴趣,这里是我的 LTAnnotation 实现
@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
这一切结合起来产生了这个......
替代文字 http://img340.imageshack.us/img340/3788/picture1fg.png
我哪里出错了有什么想法吗?谢谢