MKMapview change annotation image
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id<MKAnnotation>)annotation {
NSLog(@"annotion");
CGSize imgSize;
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"pin";
pinView = (MKAnnotationView *)
[self.m_mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.canShowCallout = NO;
pinView.image = [UIImage imageName:@"blue.jpg"];
return pinView;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
view.image = [UIImage imageName:@"orange.jpg"]
}
I have added annotations to the mapView with the image (like a blue image). When I click on annotation, I changed the image (i.e. the orange image). then I click on another annotation change annotation (i.e. image with image) to (i.e. blue image) and change the selected annotation to (i.e. image). Any help will be described in advance. Preliminary
+3
source to share
2 answers
Try this, it might be helpful.
Reload all other annotations.
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView (MKAnnotationView *)view{
for (id<MKAnnotation> annotation in mapView.annotations){
MKAnnotationView* anView = [mapView viewForAnnotation: annotation];
if (anView){
anView.image = [UIImage imageNamed:@"blue.jpg"];
}
}
view.image = [UIImage imageName:@"orange.jpg"];
}
Try it
+4
source to share