我试图从json的地图上显示信息,但没有任何反应我认为有些东西丢失,因此信息可以显示在地图上 管理让json工作并获取有关信息日志,现在我想知道谁来创建nsdictionary和数组,以便我可以显示mapview上的信息。 这里是战争我迄今为止与阵列:json注解不显示在地图上
NSData *data =[NSData dataWithContentsOfURL:[NSURL URLWithString:@"URL"]];
NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"Datos Obtenidos:\n%@",dict);
NSDictionary *cortes;
NSError* error;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
NSMutableArray *jsonCheckins = [NSMutableArray array];
for(NSDictionary *jsonElement in jsonArray){
InitViewController *checkin = [InitViewController checkinFromDictionary:jsonElement];
[jsonCheckins addObject:checkin];
}
管理添加此代码,但仍然是信息不showning上的MapView:
- (CLLocationCoordinate2D) checkinCoordinate {
CLLocationCoordinate2D coordinate;
coordinate.latitude = self.checkin.latitud;
coordinate.longitude = self.checkin.longitud;
return coordinate;}
- (void)showCheckinAnnotation {
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = [self checkinCoordinate];
annotationPoint.title = self.checkin.type;
annotationPoint.subtitle = self.checkin.description;
[self.mapView addAnnotation:annotationPoint];}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *annotationView= nil;
if(annotation != mapView.userLocation) {
static NSString *annotationViewId = @"annotationViewId";
annotationView = (MKAnnotationView *)[mapView
dequeueReusableAnnotationViewWithIdentifier:annotationViewId];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationViewId];
}
}
return annotationView;}
您确定addAnnotation行正在执行并且坐标正确吗?另外请注意,您正在创建一个普通的MKAnnotationView,默认情况下它是空的,除非您添加内容或设置图像。尝试创建MKPinAnnotationView,或者完全删除viewForAnnotation方法以获取默认的视图视图。 – Anna 2013-05-02 03:14:22
同意,'MKPinAnnotationView'是关键问题,但是在'viewForAnnotation'中存在另一个小问题,在'dequeueReusableAnnotationViewWithIdentifier'成功的情况下,你永远不会设置注释。此外,你不共享'checkinFromDictionary',但你的其他方法使用'self.checkin',但你从来没有设置('checkin'是你的第一个方法的局部变量,所以希望这不是你的意思,因为赢得了没有工作)。 – Rob 2013-05-02 04:01:26