Question

Edited to Add * I haven't found a solution for this one yet, can anyone please help? My problem is similar to this but the answer posted doesn't t work for me - MKMapView refresh after pin moves *End Edit

I have a search enabled map view. When user hits search, my custom annotations are added to the map view. The search returns 20 results with a 'load more' link. When I hit load more, more annotations should be added to map view.

The problem is - annotations gets added to the map view but is not displayed on the map. If I zoom in or zoom out to change the map region, the pins are shown.

I find that viewForAnnotations: is not getting called when i hit 'load more'. I am not sure how to trigger this. any one?

-(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
Was it helpful?

Solution 2

This had something to do with the time lapse receiving the notification and then adding the annotation pins. Forcing it to use the main thread to add annotation pins worked.

OTHER TIPS

just wanted to confirm i was adding annotations from a thread - which doesnt work. once I used this (addCameraIconOnMain adds my annoations)

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

its worked! thanks!

in my case the problem was I was adding the annotation before the map delegate. It must be something like:

- (void)viewDidLoad
{
    ...

   // map delegate
   [mView setDelegate:self];

   ...

   // add annotation
   [_map addAnnotation:_poiAnnotation];

   ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top