Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem adding multiple annotations to map
    text
    copied!<p>Ok, so I’m having this problem. What I want to do is manually add multiple annotations to a map. When I add just one annotation, it works flawlessly. The pin drops, you can click on it to see its callout, life is good.</p> <p>The problem comes when I want to add more than one. When I add the second, suddenly the pin’s aren’t coloured correctly (i.e. depending on their magnitude they should be a certain color, but they’re now both the same…), and more importantly when you click on them, to see their callout, the app crashes with exex_bad_access. I really have no idea what’s wrong, maybe I’m adding too many views to the map? But it’s only 9 pins and the pins themselves add just fine. Here’s my code…</p> <pre><code> - (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *stops = [[NSMutableArray alloc] init]; //Get list of all the stops available Bus *bus1 = [[Bus alloc] init]; // Bus 1 holds the stops stops = [bus1 returnStops]; for (NSString *stop in stops) //Go through each stop to add annotation to map { Bus *bus2 = [bus1 initWithStop:stop]; //Create an instance of bus with a given stop MapAnnotation *eqAnn = [MapAnnotation annotationWithBus:bus2]; [self.mapView addAnnotation:eqAnn]; //Add the annotation to the map //[eqAnn release]; //[bus2 release]; } [self recenterMap]; [stops release]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { MKAnnotationView *view = nil; if(annotation != mapView.userLocation) { MapAnnotation *eqAnn = (MapAnnotation*)annotation; view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"busLoc"]; if(nil == view) { view = [[[MKPinAnnotationView alloc] initWithAnnotation:eqAnn reuseIdentifier:@"busLoc"] autorelease]; } CGFloat magnituide = [eqAnn.bus.magnitude floatValue]; if(magnituide &gt;= .80f) { [(MKPinAnnotationView *)view setPinColor:MKPinAnnotationColorRed]; } else if(magnituide &gt;= .60f) { [(MKPinAnnotationView *)view setPinColor:MKPinAnnotationColorPurple]; } else { [(MKPinAnnotationView *)view setPinColor:MKPinAnnotationColorGreen]; } [(MKPinAnnotationView *)view setAnimatesDrop:YES]; [view setCanShowCallout:YES]; } return view; } </code></pre> <p>even tried removing the second function, but it didn’t do anything.</p> <p>Thanks for the help! P.S I should also add, there’s usually one or two pins out of the 9 which works when you click the annotation…</p> <p>If i even try to manually just two annotations by hand in the program (i.e., remove the loop), it still fails and the color is still wrong...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload