У меня есть метод, который вставляет аннотации на карту. Этот метод вызывается методом делегирования карты.MKAnnotation не отображаются на карте, используя NSThread
Проблема в том, что аннотации не отображаются на карте. Я должен коснуться карты еще раз, чтобы показать аннотации.
После вставки аннотаций я использую [CATRansaction flush], но это не работает.
Над кодом:
Карта делегирован метод:
- (void) mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{ log(@"region changed"); if (_userRegion.center.latitude) { log(@"Move map. New location: %f X %f", self.mapView.centerCoordinate.latitude, self.mapView.centerCoordinate.longitude); NSDictionary *coordinates = @{ @"latitude": [NSString stringWithFormat:@"%f", self.mapView.centerCoordinate.latitude], @"longitude": [NSString stringWithFormat:@"%f", self.mapView.centerCoordinate.longitude] }; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(updateMap:) object:coordinates]; [thread start]; } if(_userMenuOpened){ [self closeUserMenu]; } if(_settingsMenuOpened){ [self closeSettingsMenu]; } }
Метод, который вставляет аннотацию:
- (void) updateMap:(NSDictionary *) coordinates { NSArray *annotationsInMap = [self.mapView annotations]; _busStops = [_ws getStations:10 lat:[[coordinates valueForKey:@"latitude"] doubleValue] lng:[[coordinates valueForKey:@"longitude"] doubleValue]]; for(NSString *stop in _busStops) { BOOL inMap = NO; BPBusStopAnnotation *annotation = [[BPBusStopAnnotation alloc] initWithData:stop]; //Se tiver annotation no mapa verifica se os que vem no WS sao os mesmos if(annotationsInMap.count > 0){ for(BPBusStopAnnotation *pt in annotationsInMap){ if(pt && ![pt isKindOfClass:[MKUserLocation class]]){ if([annotation.codigo isEqual:pt.codigo]){ inMap = YES; break; } } } } if (!inMap) { [self.mapView addAnnotation:annotation]; } } [CATransaction flush]; }
Спасибо !!!-х
по теме: http://stackoverflow.com/questions/1995245/iphone-mapview-interrupted – Anna