MKMapView - viewForAnnotation is not called when loading more results

Edited to add * I have not yet found a solution for this, can anyone help? My problem is similar to this, but the answer you sent does not work for me - Update MKMapView after moving the cursor * End Edit

I have a map display with search support. When a user clicks on a search, my user annotations are added to the map view. A search returns 20 results with a “download more” link. When I click more downloads, more annotations should be added to the map view.

Problem - Annotations are added to the map view, but not displayed on the map. If I zoomed in or zoomed out to change the area of ​​the map, contacts will be shown.

I find viewForAnnotations: does not receive a call when I click "load more". I am not sure how to trigger this. any?

-(void)completedSearch:(NSNotification *)resultNotification
 {
   //begin loop
   //get coordinate
   customAnnotation *annot = [[customAnnotation alloc] initWithCoordinate:coordinate];
   //set title subtitle 
   [annotationsArray addObject:annot];
   //end loop
   [mView addAnnotations:annotationsArray];
   [mView setRegion:region animated:YES];
   [mView regionThatFits:region];
 }

  //custom annotation
  @interface customAnnotation : NSObject <MKAnnotation> 
 { 
   CLLocationCoordinate2D coordinate;  
   NSString*              title; 
   NSString*              info; 
 } 
 @property (nonatomic, retain) NSSting *title;
 @property (nonatomic, retain) NSSting *info;

 -(id) initWithCoordinate:(CLLocationCoordinate2D)c;
 @end

 @implementation customAnnotation
 @synthesize coordinate, title, info;
 -(id) initWithCoordinate:(CLLocationCoordinate2D)c
 {
   coordinate = c;
   return self;
 }
 -(void)dealloc{//dealloc stuff here}
 @end
+3
source share
3 answers

This had something to do with the time received by the notification and then the addition of notes. Forcing him to use the main thread to add annotation handlers.

+1
source

I just wanted to confirm. I added annotations from the stream - this does not work. once i used this (addCameraIconOnMain adds my annotations)

[self performSelectorOnMainThread:@selector(addCameraIconOnMain:) withObject:cd waitUntilDone:true];    

! !

+4

, . - :

- (void)viewDidLoad
{
    ...

   // map delegate
   [mView setDelegate:self];

   ...

   // add annotation
   [_map addAnnotation:_poiAnnotation];

   ...
}
0

Source: https://habr.com/ru/post/1738079/


All Articles