I have used annotation map and used more than one image for the pins but whenever I zoom in or zoom out, it changes all the pins to one image.
I get the locations from a web service and to recognise them, I used a string (CustAttr
) as "T" or "P".
The problem is the last call from a web service makes the CustAttr = T
and when I zoom in or zoom out, it calls the mapView viewForAnnotation
method and draws them all as T
and all the P
pins are changed.
Here is the code for the method :
-(MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
static NSString* AnnotationIndentifer = @"AnnotationIdentifier";
if ([custAttr isEqualToString:@"T"]) // ATMs
{
MKAnnotationView* pinView;
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIndentifer];
MapAnnotation* mapAnnotation = annotation;
pinView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
pinView.rightCalloutAccessoryView = rightButton;
if (mapAnnotation.isClosest) {
pinView.image = [UIImage imageNamed:@"Closest_ATM.png"];
}
if (mapAnnotation.isOffline) {
pinView.image = [UIImage imageNamed:@"Offline_ATM.png"];
}
pinView.annotation = annotation;
return pinView;
}else if ([custAttr isEqualToString:@"P"]) // POIs
{
MKAnnotationView* pinView;
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIndentifer];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"Location_POI.png"];
pinView.annotation = annotation;
return pinView;
}
return nil;
}
How can I resolve this issue? Is there a way that I can prevent it from calling this method when zooming in/out or is there another way to let it draw them again as in the same image?