我正在尝试从 json 在地图上显示信息,但没有任何反应 我认为缺少某些信息,因此可以在地图上显示信息创建 nsdictionary 和数组,以便我可以在 mapview 上显示信息。这是迄今为止我与阵列的战争:
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];
}
设法添加此代码,但地图视图上仍未显示信息:
- (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;}