karthi k
karthi k

Reputation: 33

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 added annotations on mapView with image(i.e blue image).When i tap a annotation i changed image (i.e. orange image). then i tap on another annotation change annotation(i.e.orange image) to (i.e blue image) and change selected annotation to (i.e.orange image).any help will be appricated.thanks in advance

Upvotes: 3

Views: 5182

Answers (2)

Jogendra.Com
Jogendra.Com

Reputation: 6454

Try like this, may 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 this

Upvotes: 4

ravi sendhav
ravi sendhav

Reputation: 177

for swift 3.0

for annotation: MKAnnotation in mapView.annotations { 

    let anView = mapView.view(for: annotation)

    if (anView != nil) 
    {
        anView?.image = UIImage(named: "home_pin")
    }
}

view.image = UIImage(named: "home_pin01")

Upvotes: 3

Related Questions