I have a MKMapView with a lot of annotation pins defined from a parser xml; thats my code:
-(IBAction)LoadAnnotation:(id)sender {
RXML element ...
RXML iterate....
[myMap removeAnnotations:myMap.annotations];
annotation.title = // NSString from RXML parser
annotation.subtitle = // NSString from RXML parser
myValue = // float value from RXML parser
[mymap addAnnotation:annotation];
}
and then
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation2 {
MKPinAnnotationView *pinView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation2 reuseIdentifier:@"MyPin"];
if ( myValue > 0 && myValue < 10) {
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorRed;
pinView.animatesDrop=YES;
return pinView;
}
else if ( myValue > 10 && myValue < 20 ) {
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.animatesDrop=YES;
return pinView;
}
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.animatesDrop=YES;
return pinView;
}
All right, when my MKMapView is loaded, I can see title annotations, subtitle annotations and all the pins with different colours.
But if I scroll and zoom IN the map at a certain level, then zoom OUT again, all the pins become PURPLE. What's happening there?
I have tried also using same "annotation" (id) in the two methods (and not "annotation" and "annotation2"), but I have no result.
Is there a way to avoid that and keep pinColors after map scroll and zoom?