我使用下面的循环来填充我的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
这一切都结合起来产生了这个......
alt text http://img340.imageshack.us/img340/3788/picture1fg.png
我出错的地方有什么想法吗? 感谢
答案 0 :(得分:1)
尝试将纬度和经度设置为浮点数。
答案 1 :(得分:1)
我注意到的两件小事可能有助于解决问题:
最重要的是,我在你的init方法中注意到了这一点:
latitude = [latDbl doubleValue];
longitude = [longDbl doubleValue];
您没有使用Objective-C 2样式存取方法(self.latitude = ...)而不保留自动释放的值。这可能意味着变量正在消失,这就是为什么你看不到注释,因为它们没有有效的坐标。